Overview
TheTensor class is the fundamental data structure in Neurenix, representing multi-dimensional arrays with support for automatic differentiation, device placement, and hardware acceleration.
Creating Tensors
- From Data
- Initialization Functions
- With Device
Data Types
Neurenix supports multiple data types through theDType enum:
Tensor Properties
Tensor Operations
Arithmetic Operations
Shape Manipulation
Aggregation Operations
- Reduction
- Combining
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 memoryBatch 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 usageCommon Patterns
Training Loop
Inference
API Reference Summary
Related Documentation
- Architecture - Understanding device management
- Devices - Device types and hardware detection
- Neural Networks - Building models with tensors