snowflake.ml.jobs.MLJob¶
- class snowflake.ml.jobs.MLJob(id: str, service_spec: Optional[dict[str, Any]] = None, session: Optional[Session] = None)¶
Bases:
Generic[T],SerializableSessionMixinMethods
- cancel() None¶
Cancel the running job. :raises RuntimeError: If cancellation fails. # noqa: DAR401
- distributed_result(timeout: float = - 1) DistributedResult¶
Block until completion, then return the structured per-instance summary of a distributed run.
This is the result API for distributed jobs (e.g. submitted with
parallel=True), which have no single head result. On full success it returns aDistributedResult(success, per-instanceexit_codes,failed_instance, instance 0’sreturn_value). On any instance failure it raisesDistributedJobError, which carries that sameDistributedResultas.resultand the earliest-failing instance’s reconstructed exception as its cause.result()remains the single-head API.- Parameters:
timeout – The maximum time to wait in seconds. Negative values are treated as no timeout.
- Returns:
The reduced per-instance result, on full success. # noqa: DAR401
- Return type:
DistributedResult
- Raises:
NotImplementedError – If the job was not launched with a distributed backend (e.g.
parallel=True); single-head jobs have no per-instance result — useresult().DistributedJobError – If any instance did not exit 0. Carries the DistributedResult (
.result) with per-instanceexit_codes/failed_instance. # noqa: DAR402RuntimeError – If the job’s per-instance records could not be retrieved.
TimeoutError – If the job does not complete within the specified timeout. # noqa: DAR402
- get_logs(limit: int = - 1, instance_id: Optional[int] = None, *, as_list: Literal[True], verbose: bool = constants.DEFAULT_VERBOSE_LOG) list[str]¶
- get_logs(limit: int = - 1, instance_id: Optional[int] = None, *, as_list: Literal[False] = False, verbose: bool = constants.DEFAULT_VERBOSE_LOG) str
Return the job’s execution logs.
- Parameters:
limit – The maximum number of lines to return. Negative values are treated as no limit.
instance_id – Optional instance ID to get logs from a specific instance. If not provided, returns logs from the head node.
as_list – If True, returns logs as a list of lines. Otherwise, returns logs as a single string.
verbose – Whether to return the full log or just the user log.
- Returns:
The job’s execution logs.
- get_ray_dashboard_url() Optional[str]¶
Get the Ray dashboard URL for the job.
- Returns:
- The Ray dashboard URL if the job is running and has a Ray dashboard endpoint,
None otherwise.
- Return type:
Optional[str]
- result(timeout: float = - 1) T¶
Block until completion. Returns job execution result.
- Parameters:
timeout – The maximum time to wait in seconds. Negative values are treated as no timeout.
- Returns:
The deserialized job result. # noqa: DAR401
- Return type:
T
- Raises:
RuntimeError – If the job failed or if the job doesn’t have a result to retrieve.
TimeoutError – If the job does not complete within the specified timeout. # noqa: DAR402
- show_logs(limit: int = - 1, instance_id: Optional[int] = None, verbose: bool = False) None¶
Display the job’s execution logs.
- Parameters:
limit – The maximum number of lines to display. Negative values are treated as no limit.
instance_id – Optional instance ID to get logs from a specific instance. If not provided, displays logs from the head node.
verbose – Whether to return the full log or just the user log.
- wait(timeout: float = - 1) Literal['PENDING', 'RUNNING', 'FAILED', 'DONE', 'CANCELLING', 'CANCELLED', 'INTERNAL_ERROR', 'DELETED']¶
Block until completion. Returns completion status.
- Parameters:
timeout – The maximum time to wait in seconds. Negative values are treated as no timeout.
- Returns:
The job’s completion status.
- Raises:
TimeoutError – If the job does not complete within the specified timeout.
Attributes
- id¶
Get the unique job ID
- min_instances¶
- name¶
- session¶
- status¶
Get the job’s execution status.
- target_instances¶