This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

launch-library

Classes

class LaunchAgent: Launch agent class which polls run given run queues and launches runs for wandb launch.

Functions

launch(...): Launch a W&B launch experiment.

launch_add(...): Enqueue a W&B launch experiment. With either a source uri, job or docker_image.

1 - launch

Launch a W&B launch experiment.

launch(
    api: Api,
    job: Optional[str] = None,
    entry_point: Optional[List[str]] = None,
    version: Optional[str] = None,
    name: Optional[str] = None,
    resource: Optional[str] = None,
    resource_args: Optional[Dict[str, Any]] = None,
    project: Optional[str] = None,
    entity: Optional[str] = None,
    docker_image: Optional[str] = None,
    config: Optional[Dict[str, Any]] = None,
    synchronous: Optional[bool] = (True),
    run_id: Optional[str] = None,
    repository: Optional[str] = None
) -> AbstractRun
Arguments
jobstring reference to a wandb.Job eg: wandb/test/my-job:latest
apiAn instance of a wandb Api from wandb.apis.internal.
entry_pointEntry point to run within the project. Defaults to using the entry point used in the original run for wandb URIs, or main.py for git repository URIs.
versionFor Git-based projects, either a commit hash or a branch name.
nameName run under which to launch the run.
resourceExecution backend for the run.
resource_argsResource related arguments for launching runs onto a remote backend. Will be stored on the constructed launch config under resource_args.
projectTarget project to send launched run to
entityTarget entity to send launched run to
configA dictionary containing the configuration for the run. May also contain resource specific arguments under the key “resource_args”.
synchronousWhether to block while waiting for a run to complete. Defaults to True. Note that if synchronous is False and backend is “local-container”, this method will return, but the current process will block when exiting until the local run completes. If the current process is interrupted, any asynchronous runs launched via this method will be terminated. If synchronous is True and the run fails, the current process will error out as well.
run_idID for the run (To ultimately replace the :name: field)
repositorystring name of repository path for remote registry

Example:

from wandb.sdk.launch import launch

job = "wandb/jobs/Hello World:latest"
params = {"epochs": 5}
# Run W&B project and create a reproducible docker environment
# on a local host
api = wandb.apis.internal.Api()
launch(api, job, parameters=params)
Returns
an instance ofwandb.launch.SubmittedRun exposing information (e.g. run ID) about the launched run.
Raises
wandb.exceptions.ExecutionError If a run launched in blocking mode is unsuccessful.

2 - launch_add

Enqueue a W&B launch experiment. With either a source uri, job or docker_image.

launch_add(
    uri: Optional[str] = None,
    job: Optional[str] = None,
    config: Optional[Dict[str, Any]] = None,
    template_variables: Optional[Dict[str, Union[float, int, str]]] = None,
    project: Optional[str] = None,
    entity: Optional[str] = None,
    queue_name: Optional[str] = None,
    resource: Optional[str] = None,
    entry_point: Optional[List[str]] = None,
    name: Optional[str] = None,
    version: Optional[str] = None,
    docker_image: Optional[str] = None,
    project_queue: Optional[str] = None,
    resource_args: Optional[Dict[str, Any]] = None,
    run_id: Optional[str] = None,
    build: Optional[bool] = (False),
    repository: Optional[str] = None,
    sweep_id: Optional[str] = None,
    author: Optional[str] = None,
    priority: Optional[int] = None
) -> "public.QueuedRun"
Arguments
uriURI of experiment to run. A wandb run uri or a Git repository URI.
jobstring reference to a wandb.Job eg: wandb/test/my-job:latest
configA dictionary containing the configuration for the run. May also contain resource specific arguments under the key “resource_args”
template_variablesA dictionary containing values of template variables for a run queue. Expected format of {"VAR_NAME": VAR_VALUE}
projectTarget project to send launched run to
entityTarget entity to send launched run to
queuethe name of the queue to enqueue the run to
prioritythe priority level of the job, where 1 is the highest priority
resourceExecution backend for the run: W&B provides built-in support for “local-container” backend
entry_pointEntry point to run within the project. Defaults to using the entry point used in the original run for wandb URIs, or main.py for git repository URIs.
nameName run under which to launch the run.
versionFor Git-based projects, either a commit hash or a branch name.
docker_imageThe name of the docker image to use for the run.
resource_argsResource related arguments for launching runs onto a remote backend. Will be stored on the constructed launch config under resource_args.
run_idoptional string indicating the id of the launched run
buildoptional flag defaulting to false, requires queue to be set if build, an image is created, creates a job artifact, pushes a reference to that job artifact to queue
repositoryoptional string to control the name of the remote repository, used when pushing images to a registry
project_queueoptional string to control the name of the project for the queue. Primarily used for back compatibility with project scoped queues

Example:

from wandb.sdk.launch import launch_add

project_uri = "https://github.com/wandb/examples"
params = {"alpha": 0.5, "l1_ratio": 0.01}
# Run W&B project and create a reproducible docker environment
# on a local host
api = wandb.apis.internal.Api()
launch_add(uri=project_uri, parameters=params)
Returns
an instance ofwandb.api.public.QueuedRun which gives information about the queued run, or if wait_until_started or wait_until_finished are called, gives access to the underlying Run information.
Raises
wandb.exceptions.LaunchError if unsuccessful

3 - LaunchAgent

Launch agent class which polls run given run queues and launches runs for wandb launch.

LaunchAgent(
    api: Api,
    config: Dict[str, Any]
)
Arguments
apiApi object to use for making requests to the backend.
configConfig dictionary for the agent.
Attributes
num_running_jobsReturn the number of jobs not including schedulers.
num_running_schedulersReturn just the number of schedulers.
thread_idsReturns a list of keys running thread ids for the agent.

Methods

check_sweep_state

View source

check_sweep_state(
    launch_spec, api
)

Check the state of a sweep before launching a run for the sweep.

fail_run_queue_item

View source

fail_run_queue_item(
    run_queue_item_id, message, phase, files=None
)

finish_thread_id

View source

finish_thread_id(
    thread_id, exception=None
)

Removes the job from our list for now.

get_job_and_queue

View source

get_job_and_queue()

initialized

View source

@classmethod
initialized() -> bool

Return whether the agent is initialized.

loop

View source

loop()

Loop infinitely to poll for jobs and run them.

Raises
KeyboardInterruptif the agent is requested to stop.

name

View source

@classmethod
name() -> str

Return the name of the agent.

pop_from_queue

View source

pop_from_queue(
    queue
)

Pops an item off the runqueue to run as a job.

Arguments
queueQueue to pop from.
Returns
Item popped off the queue.
Raises
Exceptionif there is an error popping from the queue.

View source

print_status() -> None

Prints the current status of the agent.

run_job

View source

run_job(
    job, queue, file_saver
)

Set up project and run the job.

Arguments
jobJob to run.

task_run_job

View source

task_run_job(
    launch_spec, job, default_config, api, job_tracker
)

update_status

View source

update_status(
    status
)

Update the status of the agent.

Arguments
statusStatus to update the agent to.