Localhost¶
- class torchx.schedulers.local_scheduler.LocalScheduler(session_name: str, cache_size: int = 100)[source]¶
Schedules on localhost. Containers are modeled as processes and certain properties of the container that are either not relevant or that cannot be enforced for localhost runs are ignored. Properties that are ignored:
Resource requirements
Resource limit enforcements
Retry policies
Retry counts (no retries supported)
Deployment preferences
- ..note:: Use this scheduler sparingly since an application
that runs successfully on a session backed by this scheduler may not work on an actual production cluster using a different scheduler.
- describe(app_id: str) → Optional[torchx.schedulers.api.DescribeAppResponse][source]¶
Describes the specified application.
- Returns
AppDef description or
None
if the app does not exist.
- log_iter(app_id: str, role_name: str, k: int = 0, regex: Optional[str] = None, since: Optional[datetime.datetime] = None, until: Optional[datetime.datetime] = None, should_tail: bool = False) → Iterable[str][source]¶
Returns an iterator to the log lines of the
k``th replica of the ``role
. The iterator ends end all qualifying log lines have been read.If the scheduler supports time-based cursors fetching log lines for custom time ranges, then the
since
,until
fields are honored, otherwise they are ignored. Not specifyingsince
anduntil
is equivalent to getting all available log lines. If theuntil
is empty, then the iterator behaves liketail -f
, following the log output until the job reaches a terminal state.The exact definition of what constitutes a log is scheduler specific. Some schedulers may consider stderr or stdout as the log, others may read the logs from a log file.
Behaviors and assumptions:
Produces an undefined-behavior if called on an app that does not exist The caller should check that the app exists using
exists(app_id)
prior to calling this method.Is not stateful, calling this method twice with same parameters returns a new iterator. Prior iteration progress is lost.
Does not always support log-tailing. Not all schedulers support live log iteration (e.g. tailing logs while the app is running). Refer to the specific scheduler’s documentation for the iterator’s behavior.
- 3.1 If the scheduler supports log-tailing, it should be controlled
by``should_tail`` parameter.
Does not guarantee log retention. It is possible that by the time this method is called, the underlying scheduler may have purged the log records for this application. If so this method raises an arbitrary exception.
If
should_tail
is True, the method only raises aStopIteration
exception when the accessible log lines have been fully exhausted and the app has reached a final state. For instance, if the app gets stuck and does not produce any log lines, then the iterator blocks until the app eventually gets killed (either via timeout or manually) at which point it raises aStopIteration
.If
should_tail
is False, the method raisesStopIteration
when there are no more logs.Need not be supported by all schedulers.
Some schedulers may support line cursors by supporting
__getitem__
(e.g.iter[50]
seeks to the 50th log line).
- Returns
An
Iterator
over log lines of the specified role replica- Raises
NotImplementedError - if the scheduler does not support log iteration –
- run_opts() → torchx.specs.api.runopts[source]¶
Returns the run configuration options expected by the scheduler. Basically a
--help
for therun
API.
- schedule(dryrun_info: torchx.specs.api.AppDryRunInfo[torchx.schedulers.local_scheduler.PopenRequest]) → str[source]¶
Same as
submit
except that it takes anAppDryRunInfo
. Implementors are encouraged to implement this method rather than directly implementingsubmit
sincesubmit
can be trivially implemented by:dryrun_info = self.submit_dryrun(app, cfg) return schedule(dryrun_info)
Image Providers¶
- class torchx.schedulers.local_scheduler.ImageProvider[source]¶
Manages downloading and setting up an on localhost. This is only needed for
LocalhostScheduler
since typically real schedulers will do this on-behalf of the user.
- class torchx.schedulers.local_scheduler.LocalDirectoryImageProvider(cfg: torchx.specs.api.RunConfig)[source]¶
Interprets the image name as the path to a directory on local host. Does not “fetch” (e.g. download) anything. Used in conjunction with
LocalScheduler
to run local binaries.The image name must be an absolute path and must exist.
Example:
fetch(Image(name="/tmp/foobar"))
returns/tmp/foobar
fetch(Image(name="foobar"))
raisesValueError
fetch(Image(name="/tmp/dir/that/does/not_exist"))
raisesValueError