Examples
The docs/source/user_guide/examples/ directory in this repository contains self-contained scripts demonstrating common Torch-Spyre use cases.
Available Examples
Script |
Description |
|---|---|
|
Creating and allocating tensors on the Spyre device |
|
Computing softmax on Spyre |
|
Computing GELU activation on Spyre |
|
Computing mean reduction on Spyre |
|
Element-wise multiplication on Spyre |
|
Computing softplus activation on Spyre |
|
Using Spyre compiler hints to control tiling |
Distributed Examples
Script |
Description |
|---|---|
|
AllGather collective on Spyre |
|
AllReduce collective on Spyre |
|
Barrier synchronization on Spyre |
|
Broadcast collective on Spyre |
|
Gather collective on Spyre |
|
Reduce collective on Spyre |
Running an Example
python docs/source/user_guide/examples/tensor_allocate.py
python docs/source/user_guide/examples/softmax.py
Writing Your Own Example
A minimal Torch-Spyre script follows this pattern:
import torch
DEVICE = torch.device("spyre")
# Move data to device
x = torch.rand(512, 1024, dtype=torch.float16).to(DEVICE)
# Run computation (optionally with torch.compile)
output = torch.some_op(x)
# Move result back to CPU for inspection
print(output.cpu())