MCPcopy
hub / github.com/tinygrad/tinygrad / shard

Method shard

tinygrad/tensor.py:383–397  ·  view source on GitHub ↗

Shards the tensor across the given devices. Optionally specify which axis to shard on. ```python exec="true" source="above" session="tensor" result="python" t = Tensor.empty(2, 4) print(t.shard((t.device, t.device), axis=1).uop) ```

(self, devices:tuple[str, ...], axis:int|None=None)

Source from the content-addressed store, hash-verified

381 return self.replace(real)
382
383 def shard(self, devices:tuple[str, ...], axis:int|None=None) -> Tensor:
384 """
385 Shards the tensor across the given devices. Optionally specify which axis to shard on.
386
387 ```python exec="true" source="above" session="tensor" result="python"
388 t = Tensor.empty(2, 4)
389 print(t.shard((t.device, t.device), axis=1).uop)
390 ```
391 """
392 if self.uop.device is None: return self
393 if not isinstance(self.device, str): raise RuntimeError("can't shard a multi-device tensor")
394 if len(devices) == 1: return self.to(devices[0])
395 devices = cast(tuple[str, ...], canonicalize_device(devices))
396 uop = self.uop.shard(devices, self._resolve_dim(axis)) if axis is not None else self.uop.copy_to_device(devices)
397 return Tensor(uop).is_param_(self.is_param)
398
399 def shard_(self, devices:tuple[str, ...], axis:int|None=None) -> Tensor:
400 """

Callers 8

shard_Method · 0.95
shard_likeMethod · 0.95
test_embeddingMethod · 0.95
test_from_npyMethod · 0.95
test_forward_match_mpMethod · 0.95
test_forward_match_dpMethod · 0.95
_multi_likeMethod · 0.45

Calls 7

toMethod · 0.95
canonicalize_deviceFunction · 0.90
castFunction · 0.85
TensorClass · 0.85
_resolve_dimMethod · 0.80
copy_to_deviceMethod · 0.80
is_param_Method · 0.80

Tested by 5

test_embeddingMethod · 0.76
test_from_npyMethod · 0.76
test_forward_match_mpMethod · 0.76
test_forward_match_dpMethod · 0.76