mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-27 18:03:48 +08:00
eefc084302
version: sunnypilot v2025.003.000 (dev) date: 2025-12-18T05:48:43 master commit: 16c052af0835f049a67b80251d8cc1114fc08bb4
18 lines
414 B
Python
18 lines
414 B
Python
from tinygrad import Tensor, TinyJit, Device
|
|
import numpy as np
|
|
|
|
GPUS = 4
|
|
N = 128
|
|
ds = tuple([Device.canonicalize(f"{Device.DEFAULT}:{i}") for i in range(GPUS)])
|
|
t = Tensor.rand(N, N, N).shard(ds, 0)
|
|
n = t.numpy()
|
|
|
|
@TinyJit
|
|
def allreduce(t:Tensor) -> Tensor:
|
|
return t.sum(0) #.realize()
|
|
|
|
for i in range(10):
|
|
print(i)
|
|
tn = allreduce(t).numpy()
|
|
np.testing.assert_allclose(tn, n.sum(0), atol=1e-4, rtol=1e-4)
|