execute_sampling_operation
async
¶
execute_sampling_operation(
training_session_name: TrainingSessionName,
operation_config: SampleOperationConfig,
*,
config_overrides: Optional[AsyncSageMakerTrainingSessionRuntimeClientConfig] = None,
) -> ExecuteSamplingOperationOutput
Submits an asynchronous sampling operation to generate text or compute log-probabilities from the model associated with the specified training session. The session must be in Running or Blocked state. Use GetSamplingOperationResult to poll for the result.
Parameters:
-
training_session_name(TrainingSessionName) –The name of the training session to sample from.
-
operation_config(SampleOperationConfig) –The configuration for the sample operation. Specify either a sample configuration to generate text or a computeLogprobs configuration to compute token log-probabilities.
Raises:
-
ConflictException–The training session is in a state that cannot accept new operations. The session must be in
RunningorBlockedstate 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:
Generate samples from a prompt
Generates completions for a tokenized prompt using the session's current weights. Generation behavior is controlled by samplingParams, and the operation is dispatched asynchronously.
>>> await client.execute_sampling_operation(training_session_name='my-training-session', operation_config={'sample': {'prompt': {'chunks': [{'tokens': [791, 6864, 315, 9822, 374], 'type': 'encoded_text'}]}, 'numSamples': 4, 'samplingParams': {'maxTokens': 1024, 'temperature': 0.7, 'topP': 0.9}}})