Skip to content

Backend Selection

Controls which array backend tiny-pytorch uses. Set the TINY_PYTORCH_BACKEND environment variable before importing to switch backends.

  • "nd" (default) -- Custom NDArray backend with CPU (C++) and CUDA support
  • "np" -- NumPy backend (useful for debugging, supports float64)
import os

os.environ["TINY_PYTORCH_BACKEND"] = "np"
import tiny_pytorch  # Will use NumPy backend

Backend selection logic for tiny-pytorch.

This module handles the selection and configuration of different array backends for tiny-pytorch. It supports multiple backends including NumPy, CPU, and CUDA, allowing users to choose the most appropriate backend for their use case.

The backend is selected via the TINY_PYTORCH_BACKEND environment variable: - "nd": Uses the custom NDArray backend (default) - "np": Uses NumPy as the backend

Environment Variables

TINY_PYTORCH_BACKEND : str, optional The backend to use. Options are "nd" (default) or "np".

Raises:

  • RuntimeError

    If an unknown backend is specified.

Examples:

>>> import os
>>> os.environ["TINY_PYTORCH_BACKEND"] = "np"
>>> import tiny_pytorch  # Will use NumPy backend