Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Foundation Models
    • All tutorials
    • Disabling request logging
    • Getting an API key
    • Batch processing
  • Yandex Cloud ML SDK
  • Compatibility with OpenAI
  • Access management
  • Pricing policy
  • Public materials
  • Release notes

In this article:

  • Getting started
  • Prepare data
  • Run the model
  1. Step-by-step guides
  2. Batch processing

Running a model in batch mode

Written by
Yandex Cloud
Updated at May 13, 2025
  • Getting started
  • Prepare data
  • Run the model

Getting started

Management console
SDK

You can start working from the management console right away.

  1. Create a service account and assign the ai.editor role to it.

  2. Get the service account API key and save it.

    The following examples use API key authentication. Yandex Cloud ML SDK also supports IAM token and OAuth token authentication. For more information, see Authentication in Yandex Cloud ML SDK.

  3. Use the pip package manager to install the ML SDK library:

    pip install yandex-cloud-ml-sdk
    

Prepare data

  1. Prepare data to run the model. Depending on your task and model, it can be TextTextToTextGenerationRequest for text generation or ImageTextToTextGenerationRequest for vision language models.
  2. Create a dataset in any convenient way. You can also create a dataset later when running the model.

Run the model

Management console
SDK
  1. In the management console, select the folder for which your account has the ai.playground.user and ai.datasets.editor roles or higher.
  2. In the list of services, select Foundation Models.
  3. In the left-hand panel, click and select Batch jobs.
  4. Click Run.
  5. Select a model to run.
  6. Add a dataset: select an existing one or upload a new file.
  7. Set the model temperature.
  8. Click Run.
  1. Create a file named batch-run.py and add the following code to it:

    #!/usr/bin/env python3
    
    from __future__ import annotations
    import pathlib
    from yandex_cloud_ml_sdk import YCloudML
    
    PATH = pathlib.Path(__file__)
    NAME = f'example-{PATH.parent.name}-{PATH.name}'
    
    
    def local_path(path: str) -> pathlib.Path:
        return pathlib.Path(__file__).parent / path
    
    
    def main() -> None:
        sdk = YCloudML(
            folder_id="<folder_ID>",
            auth="<API_key>",
        )
    
        sdk.setup_default_logging()
    
        
        model = sdk.models.completions('<model_URI>')
    
        # The batch run will return an _Operations_ object
        # You can monitor its status or call the .wait method 
        operation = model.batch.run_deferred("<dataset_ID>")
    
        resulting_dataset = operation.wait()
    
        # A dataset with results will return in Parquet format
        try:
            import pyarrow 
    
            print('Resulting dataset lines:')
            for line in resulting_dataset.read():
                print(line)
        except ImportError:
            print('skipping dataset read; install yandex-cloud-ml-sdk[datasets] to be able to read')
    
    if __name__ == '__main__':
        main()
    

    Where:

    • <folder_ID>: ID of the folder the service account was created in.
    • <API_key>: Service account API key you got earlier required for authentication in the API.

    The following examples use API key authentication. Yandex Cloud ML SDK also supports IAM token and OAuth token authentication. For more information, see Authentication in Yandex Cloud ML SDK.

    • <model_URI>: ID of the model to run. Text generation and vision language models are supported.
    • <dataset_ID>: ID of the dataset with requests to the model.
  2. Run the created file:

    python3 batch-run.py
    

Tip

The model runtime in batch mode depends on the dataset size and may take several days. You can track the current status in the management console.

Was the article helpful?

Previous
Generating an image
Next
Using prompt-based classifiers
© 2025 Direct Cursus Technology L.L.C.