bundle.lambdalabs ================= .. py:module:: bundle.lambdalabs .. autoapi-nested-parse:: Lambda Labs cloud GPU integration for TheBundle. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/bundle/lambdalabs/cli/index /autoapi/bundle/lambdalabs/client/index /autoapi/bundle/lambdalabs/config/index /autoapi/bundle/lambdalabs/models/index /autoapi/bundle/lambdalabs/runner/index Exceptions ---------- .. autoapisummary:: bundle.lambdalabs.LambdaApiError Classes ------- .. autoapisummary:: bundle.lambdalabs.LambdaClient bundle.lambdalabs.LambdaLabsConfig bundle.lambdalabs.Filesystem bundle.lambdalabs.Instance bundle.lambdalabs.InstanceStatus bundle.lambdalabs.InstanceType bundle.lambdalabs.SshKey bundle.lambdalabs.RemoteJob Package Contents ---------------- .. py:exception:: LambdaApiError(status_code: int, message: str) Bases: :py:obj:`Exception` Common base class for all non-exit exceptions. .. py:attribute:: status_code .. py:class:: LambdaClient(api_key: str) Async client for the Lambda Labs Cloud API v1. Usage: async with LambdaClient(api_key="...") as client: types = await client.instance_types() instance = await client.launch("gpu_1x_a10", ssh_key_names=["mykey"]) await client.wait_active(instance.id) await client.terminate([instance.id]) .. py:method:: instance_types() -> dict[str, bundle.lambdalabs.models.InstanceType] :async: Return available instance types keyed by name. .. py:method:: instances() -> list[bundle.lambdalabs.models.Instance] :async: Return all active instances. .. py:method:: get_instance(instance_id: str) -> bundle.lambdalabs.models.Instance :async: Return a single instance by ID. .. py:method:: filesystems() -> list[bundle.lambdalabs.models.Filesystem] :async: Return all filesystems in the account. .. py:method:: create_filesystem(name: str, region_name: str = 'us-east-1') -> bundle.lambdalabs.models.Filesystem :async: Create a persistent filesystem. .. py:method:: launch(instance_type_name: str, ssh_key_names: list[str], region_name: str = 'us-east-1', name: str | None = None, quantity: int = 1, file_system_names: list[str] | None = None) -> list[str] :async: Launch instances. Returns list of instance IDs. .. py:method:: terminate(instance_ids: list[str]) -> list[str] :async: Terminate instances. Returns list of terminated instance IDs. .. py:method:: ssh_keys() -> list[bundle.lambdalabs.models.SshKey] :async: Return all SSH keys in the account. .. py:method:: add_ssh_key(name: str, public_key: str) -> bundle.lambdalabs.models.SshKey :async: Add an SSH key to the account. .. py:method:: delete_ssh_key(key_id: str) -> None :async: Delete an SSH key by ID. .. py:method:: wait_active(instance_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL, timeout: float = 600) -> bundle.lambdalabs.models.Instance :async: Poll until the instance is active with an IP. Raises TimeoutError on timeout. .. py:class:: LambdaLabsConfig(/, **data: Any) Bases: :py:obj:`bundle.core.data.Data` Base data model class, providing utilities for serialization and deserialization from/to JSON, along with JSON Schema generation. .. attribute:: model_config Default model configuration settings. .. py:attribute:: api_key :type: str :value: '' .. py:attribute:: default_ssh_key :type: str :value: '' .. py:attribute:: default_region :type: str :value: 'us-east-1' .. py:attribute:: default_instance_type :type: str :value: 'gpu_1x_a10' .. py:attribute:: default_filesystem :type: str :value: '' .. py:method:: load() -> LambdaLabsConfig :classmethod: .. py:method:: save() -> None .. py:property:: is_configured :type: bool .. py:class:: Filesystem(/, **data: Any) Bases: :py:obj:`bundle.core.data.Data` A Lambda Labs persistent NFS filesystem. Auto-mounted on instances at ``/home/ubuntu//``. Survives instance termination — ideal for storing datasets and results across multiple training jobs without re-uploading. .. py:attribute:: id :type: str .. py:attribute:: name :type: str .. py:attribute:: region :type: dict[str, Any] .. py:attribute:: mount_point :type: str :value: '' .. py:property:: path :type: pathlib.Path Mount path on the instance. .. py:class:: Instance(/, **data: Any) Bases: :py:obj:`bundle.core.data.Data` Base data model class, providing utilities for serialization and deserialization from/to JSON, along with JSON Schema generation. .. attribute:: model_config Default model configuration settings. .. py:attribute:: id :type: str .. py:attribute:: name :type: str | None :value: None .. py:attribute:: status :type: InstanceStatus .. py:attribute:: instance_type :type: InstanceType .. py:attribute:: ip :type: str | None :value: None .. py:attribute:: region :type: dict[str, Any] .. py:attribute:: ssh_key_names :type: list[str] :value: [] .. py:attribute:: file_system_names :type: list[str] :value: [] .. py:property:: is_active :type: bool .. py:property:: is_ready :type: bool .. py:class:: InstanceStatus Bases: :py:obj:`str`, :py:obj:`enum.Enum` str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'. .. py:attribute:: BOOTING :value: 'booting' .. py:attribute:: ACTIVE :value: 'active' .. py:attribute:: UNHEALTHY :value: 'unhealthy' .. py:attribute:: TERMINATING :value: 'terminating' .. py:attribute:: TERMINATED :value: 'terminated' .. py:class:: InstanceType(/, **data: Any) Bases: :py:obj:`bundle.core.data.Data` Base data model class, providing utilities for serialization and deserialization from/to JSON, along with JSON Schema generation. .. attribute:: model_config Default model configuration settings. .. py:attribute:: name :type: str .. py:attribute:: description :type: str .. py:attribute:: price_cents_per_hour :type: int .. py:attribute:: specs :type: InstanceSpecs .. py:property:: price_per_hour :type: float .. py:class:: SshKey(/, **data: Any) Bases: :py:obj:`bundle.core.data.Data` Base data model class, providing utilities for serialization and deserialization from/to JSON, along with JSON Schema generation. .. attribute:: model_config Default model configuration settings. .. py:attribute:: id :type: str .. py:attribute:: name :type: str .. py:attribute:: public_key :type: str .. py:class:: RemoteJob(config: bundle.lambdalabs.config.LambdaLabsConfig | None = None, api_key: str | None = None, ssh_key_path: pathlib.Path | None = None, ssh_user: str = 'ubuntu', auto_terminate: bool = False, filesystem_name: str | None = None) Manages a single remote training job on Lambda Labs. Lifecycle: 1. launch() — start a GPU instance (or attach to an existing one) 2. wait() — poll until active + has IP 3. setup() — install bundle on the remote instance 4. upload() — rsync local workspace → remote (skips unchanged files) 5. run() — execute a command via SSH 6. download() — rsync remote results → local 7. terminate()— shut down the instance (optional) Filesystem mode (recommended): Pass ``filesystem_name`` to mount a Lambda Labs persistent NFS volume. The workspace lives at ``/home/ubuntu//`` and survives instance termination — images and SfM output are never re-uploaded. Only the small ``runs/`` results are downloaded after each job. .. py:attribute:: config .. py:attribute:: ssh_key_path .. py:attribute:: ssh_user :value: 'ubuntu' .. py:attribute:: auto_terminate :value: False .. py:attribute:: filesystem_name :type: str .. py:attribute:: instance :type: bundle.lambdalabs.models.Instance | None :value: None .. py:method:: launch(instance_type: str | None = None, ssh_key_name: str | None = None, region: str | None = None, name: str | None = None, instance_id: str | None = None) -> bundle.lambdalabs.models.Instance :async: Launch a new instance or attach to an existing one by ID. .. py:method:: wait(timeout: float = 600) -> bundle.lambdalabs.models.Instance :async: Poll until the instance is active with an IP. .. py:method:: setup() -> None :async: Install bundle on the remote instance. .. py:method:: upload(local: pathlib.Path, remote: pathlib.Path, skip_existing: bool = False) -> None :async: rsync local directory → remote instance. When ``skip_existing=True`` (set automatically in filesystem mode), files already on the remote are not re-transferred — saving time and bandwidth for large image datasets on subsequent runs. .. py:method:: download(remote: pathlib.Path, local: pathlib.Path) -> None :async: rsync remote directory → local. .. py:method:: run(command: str) -> None :async: Execute a shell command on the remote instance via SSH. .. py:method:: terminate() -> None :async: Terminate the instance.