tinygrad runtime.ops_torch
Note
You likely want the upstream tinygrad, not tinygrab. Tinygrab contains AI generated docstrings for a tinygrad snapshot. Upstream: https://tinygrad.org
- class tinygrad.runtime.ops_torch.TorchAllocator[source]
Bases:
Allocator
TorchAllocator Class:
This class is an implementation of the Allocator class with additional methods for memory allocation, data copying in and out. It utilizes the PyTorch library to perform operations on tensors and devices.
- None.
- copyin(dest: Tensor, src: memoryview)[source]
Copies data from a memoryview object to a PyTorch tensor.
- Parameters:
dest (torch.Tensor) – Destination PyTorch tensor.
src (memoryview) – Source memoryview object.
- Returns:
None. The contents of the source memoryview are copied into the destination PyTorch tensor.
- copyout(dest: memoryview, src: Tensor)[source]
Copies data from a PyTorch tensor to a memoryview object.
- Parameters:
dest (memoryview) – Destination memoryview object.
src (torch.Tensor) – Source PyTorch tensor.
- Returns:
None. The contents of the source PyTorch tensor are copied into the destination memoryview object.
- tinygrad.runtime.ops_torch.as_strided(x, arg)[source]
Creates a view of the original tensor with a specified stride.
- tinygrad.runtime.ops_torch.x
The input tensor.
- Type:
torch.tensor
- tinygrad.runtime.ops_torch.arg
A tuple containing the size, stride and storage offset for the output tensor.
- Type:
tuple
- Returns:
The output tensor with the specified stride.
- Return type:
torch.tensor
- tinygrad.runtime.ops_torch.match_types(x, y, disallow_bool=False)[source]
Matches the data types of two tensors and returns them cast to a specified type.
- tinygrad.runtime.ops_torch.x
The first input tensor.
- Type:
torch.tensor
- tinygrad.runtime.ops_torch.y
The second input tensor.
- Type:
torch.tensor
- tinygrad.runtime.ops_torch.disallow_bool
If True, bool data types are not allowed. Defaults to False.
- Type:
bool, optional
- Returns:
The input tensors cast to the same data type.
- Return type:
Tuple[torch.tensor, torch.tensor]
- tinygrad.runtime.ops_torch.output_type(x, y)[source]
Returns the data type of x or y based on their data type priority.
- tinygrad.runtime.ops_torch.x
The first input tensor.
- Type:
torch.tensor
- tinygrad.runtime.ops_torch.y
The second input tensor.
- Type:
torch.tensor
- Returns:
The data type of the tensor with higher priority.
- Return type:
torch.dtype