Skip to content

execute_training_operation async

execute_training_operation(
    training_session_name: TrainingSessionName,
    sequence_number: SequenceNumber,
    operation_config: OperationConfig,
    *,
    config_overrides: Optional[AsyncSageMakerTrainingSessionRuntimeClientConfig] = None,
    client_token: Optional[ClientToken] = None,
) -> ExecuteTrainingOperationOutput

Submits an asynchronous training operation to the specified training session. The service executes operations in sequence number order. The session must be in Running or Blocked state. Use GetTrainingOperationResult to poll for the result. Supported operation types: forward, forwardBackward, optimizerStep, saveWeights, saveState, and loadState.

Parameters:

  • training_session_name (TrainingSessionName) –

    The name of the training session to submit the operation to.

  • sequence_number (SequenceNumber) –

    The monotonically increasing sequence number that determines execution order. The training session processes operations strictly in sequence number order. If a gap exists, the session blocks until the missing operation arrives or times out. Must be at least 1.

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier that you provide to ensure that the operation completes no more than one time. If you retry a request with the same client token and the same parameters, the service ignores the request but does not return an error.

  • operation_config (OperationConfig) –

    The configuration that specifies the type and parameters of the training operation. Exactly one member of the union must be set.

Raises:

  • ConflictException –

    The training session is in a state that cannot accept new operations. The session must be in Running or Blocked state to accept requests.

  • InternalServerException –

    An internal service error occurred. Retry the request using exponential backoff.

  • ResourceNotFoundException –

    The specified training session or operation does not exist, or the operation does not belong to the specified training session.

  • ThrottlingException –

    The request was throttled. Retry the request after a brief wait using exponential backoff.

  • ValidationException –

    The request is not valid. Check the request syntax and parameters. Examples include invalid sequence numbers, malformed client tokens, missing required fields, or invalid operation configuration.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Run a forward and backward pass Computes gradients for a batch of tokenized prompts and accumulates them into the session. Operations are applied in sequenceNumber order, so each call must supply the next number in the sequence.

>>> await client.execute_training_operation(training_session_name='my-training-session', sequence_number=1, operation_config={'forwardBackward': {'lossFnName': 'cross_entropy', 'datumList': [{'modelInput': {'chunks': [{'tokens': [791, 6864, 315, 9822, 374, 12366], 'type': 'encoded_text'}]}}]}})
Source code in docs_src/capo_sagemakertrainingsessionruntime/_services/async_sage_maker_training_session_runtime.py
async def execute_training_operation(
    self,
    training_session_name: "capo_sagemakertrainingsessionruntime.types.training_session_name.TrainingSessionName",
    sequence_number: "capo_sagemakertrainingsessionruntime.types.sequence_number.SequenceNumber",
    operation_config: "capo_sagemakertrainingsessionruntime.types.operation_config.OperationConfig",
    *,
    config_overrides: Optional[
        AsyncSageMakerTrainingSessionRuntimeClientConfig
    ] = None,
    client_token: Optional[
        "capo_sagemakertrainingsessionruntime.types.client_token.ClientToken"
    ] = None,
) -> "capo_sagemakertrainingsessionruntime.types.execute_training_operation_output.ExecuteTrainingOperationOutput":
    """<p>Submits an asynchronous training operation to the specified training session. The service executes operations in sequence number order. The session must be in <code>Running</code> or <code>Blocked</code> state. Use <code>GetTrainingOperationResult</code> to poll for the result. Supported operation types: <code>forward</code>, <code>forwardBackward</code>, <code>optimizerStep</code>, <code>saveWeights</code>, <code>saveState</code>, and <code>loadState</code>.</p>

    Args:
        training_session_name: <p>The name of the training session to submit the operation to.</p>
        sequence_number: <p>The monotonically increasing sequence number that determines execution order. The training session processes operations strictly in sequence number order. If a gap exists, the session blocks until the missing operation arrives or times out. Must be at least 1.</p>
        client_token: <p>A unique, case-sensitive identifier that you provide to ensure that the operation completes no more than one time. If you retry a request with the same client token and the same parameters, the service ignores the request but does not return an error.</p>
        operation_config: <p>The configuration that specifies the type and parameters of the training operation. Exactly one member of the union must be set.</p>

    Raises:
        capo_sagemakertrainingsessionruntime.errors.conflict_exception.ConflictException: <p>The training session is in a state that cannot accept new operations. The session must be in <code>Running</code> or <code>Blocked</code> state to accept requests.</p>
        capo_sagemakertrainingsessionruntime.errors.internal_server_exception.InternalServerException: <p>An internal service error occurred. Retry the request using exponential backoff.</p>
        capo_sagemakertrainingsessionruntime.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified training session or operation does not exist, or the operation does not belong to the specified training session.</p>
        capo_sagemakertrainingsessionruntime.errors.throttling_exception.ThrottlingException: <p>The request was throttled. Retry the request after a brief wait using exponential backoff.</p>
        capo_sagemakertrainingsessionruntime.errors.validation_exception.ValidationException: <p>The request is not valid. Check the request syntax and parameters. Examples include invalid sequence numbers, malformed client tokens, missing required fields, or invalid operation configuration.</p>
        capo_sagemakertrainingsessionruntime.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Run a forward and backward pass
        Computes gradients for a batch of tokenized prompts and accumulates them into the session. Operations are applied in `sequenceNumber` order, so each call must supply the next number in the sequence.

        >>> await client.execute_training_operation(training_session_name='my-training-session', sequence_number=1, operation_config={'forwardBackward': {'lossFnName': 'cross_entropy', 'datumList': [{'modelInput': {'chunks': [{'tokens': [791, 6864, 315, 9822, 374, 12366], 'type': 'encoded_text'}]}}]}})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_sagemakertrainingsessionruntime.types.execute_training_operation_input.ExecuteTrainingOperationInput]",
    ) -> AsyncOperationResponse[
        "capo_sagemakertrainingsessionruntime.types.execute_training_operation_output.ExecuteTrainingOperationOutput"
    ]:
        import capo_sagemakertrainingsessionruntime._operations.lego_router_service.execute_training_operation

        (
            output,
            http_response,
        ) = await capo_sagemakertrainingsessionruntime._operations.lego_router_service.execute_training_operation.async_execute_training_operation(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_sagemakertrainingsessionruntime.types.execute_training_operation_input.ExecuteTrainingOperationInput",
    ) -> dict[str, Any]:
        import capo_sagemakertrainingsessionruntime.types.execute_training_operation_input

        return capo_sagemakertrainingsessionruntime.types.execute_training_operation_input.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("ExecuteTrainingOperation", redact_input=_redact_input),
    )
    input_: capo_sagemakertrainingsessionruntime.types.execute_training_operation_input.ExecuteTrainingOperationInput = {
        "training_session_name": training_session_name,
        "sequence_number": sequence_number,
        "operation_config": operation_config,
    }
    if client_token is not None:
        input_["client_token"] = client_token

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output