OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Developer Tools & SDKs

Toma

Toma is a Python helper library for PyTorch algorithms that adapt to available CUDA memory by retrying out-of-memory operations with smaller batch or step sizes. It also provides caching for successful batch sizes.

Independent OpenViST project profile, based on linked sources.

Toma — Adapting PyTorch batch sizes to available CUDA memory
OpenViST project illustration. See the linked sources for product details.
Understand the project

Practical overview

When it fits

Consider Toma for otherwise costly PyTorch operations where available CUDA memory varies or the initial batch or step size may be too large. The project cautions that its retry and cache machinery adds overhead.

Who it is for

  • PyTorch developers handling workloads that may exceed available CUDA memory.
  • Practitioners who want batch, range or chunked processing to retry at smaller sizes after memory failures.

Documented uses

  • Retry an inference or training function with a reduced batch size after an out-of-memory error.
  • Process tensor data in chunks and reduce the chunk step when memory errors occur.
  • Iterate over a range with a step size that can be reduced after an out-of-memory error.
  • Reuse successful batch sizes through a configurable cache.
Before you choose

Requirements & limits

The public repository identifies Toma as open source under the MIT license and documents installation with pip.

  • The batch helper retries a function with a lower batch size; range and chunked helpers adapt iteration step sizes.
  • Three cache modes are documented: stacktrace and available-memory based by default, global per function, or none.
  • The default cache assumes memory usage stabilizes after a few iterations.
  • The library adds overhead and is recommended for operations that are otherwise time- and memory-consuming.

Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.

Source-based practical guide

Install Toma and prepare an adaptive batch function

Install the library and structure a PyTorch function to use Toma's documented batch helper.

Before you start

  • Python environment with pip
  • A PyTorch workload function that accepts a batchsize argument

Steps

  1. Install the package with the command below.

    Documented command
    pip install toma
  2. Import toma with from toma import toma.

  3. Decorate the workload function with @toma.batch(initial_batchsize=512) or another chosen initial batch size.

  4. Call the function with its model and dataset arguments.

Expected outcome

The helper attempts the initial batch size and, after a memory error, reduces the batch size and retries.

Guide limitations

  • Toma adds overhead; its documentation recommends using it with otherwise time- and memory-consuming operations.
  • The documented batch size can differ from the batch size used for gradient accumulation.
Source-based practical guide

Choose a batch-size cache

Configure how Toma remembers successful batch sizes.

Before you start

  • Toma installed in a Python project

Steps

  1. Choose the default StacktraceMemoryBatchsizeCache, GlobalBatchsizeCache, or NoBatchsizeCache.

  2. Pass the selected type through the call's cache_type argument, or set toma.DEFAULT_CACHE_TYPE.

  3. For example, use @toma.batch(initial_batchsize=512, cache_type=toma.GlobalBatchsizeCache) for a per-function cache.

Expected outcome

The selected cache behavior is used for batch-size retries: the default considers call trace and available memory, the global cache reuses a successful size per function, and no-cache mode starts from the suggested size each time.

Guide limitations

  • The default cache assumes GPU and CPU memory use reaches a stable state after a few iterations.
  • No-cache mode does not reuse a successful batch size.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
14 November 2026
Original website title
BlackHC/toma · Official homepage title · retained in its source language