Skip to main content

Overview

The Tensor class is the fundamental data structure in Neurenix, representing multi-dimensional arrays with support for automatic differentiation, device placement, and hardware acceleration.

Creating Tensors

Data Types

Neurenix supports multiple data types through the DType enum:

Tensor Properties

Tensor Operations

Arithmetic Operations

Shape Manipulation

Aggregation Operations

Activation Functions

Tensors have built-in activation functions:

Advanced Activations

Device Management

Moving Tensors Between Devices

The to() method creates a new tensor on the target device. For in-place device switching, use hot_swap_device().

Hot-Swapping Devices

hot_swap_device() modifies the tensor in-place, which is more memory-efficient than creating a new tensor with to().

NumPy Interoperability

Automatic Differentiation

Enable gradient tracking for automatic differentiation:

Gradient Context Managers

Advanced Tensor Operations

Gather Operation

Cloning and Clamping

Static Methods

Performance Tips

Use In-Place Operations

Methods like relu(inplace=True) modify tensors in-place, saving memory

Batch Operations

Operate on batched tensors instead of loops for better performance

Device Placement

Create tensors on the target device to avoid unnecessary transfers

Disable Gradients

Use Tensor.no_grad() during inference to reduce memory usage

Common Patterns

Training Loop

Inference

API Reference Summary