MCPcopy
hub / github.com/tinygrad/tinygrad / to

Method to

tinygrad/tensor.py:365–373  ·  view source on GitHub ↗

Moves the tensor to the given device.

(self, device:str|tuple[str, ...]|None)

Source from the content-addressed store, hash-verified

363 return ret.is_param_(self.is_param)
364
365 def to(self, device:str|tuple[str, ...]|None) -> Tensor:
366 """
367 Moves the tensor to the given device.
368 """
369 if self.uop.device is None: return self
370 if (device:=canonicalize_device(device)) == self.device: return self
371 ret = Tensor(self.uop.copy_to_device(device))
372 if self.grad is not None: ret.grad = self.grad.to(device)
373 return ret.is_param_(self.is_param)
374
375 def to_(self, device:str|tuple[str, ...]|None) -> Tensor:
376 """

Callers 15

to_Method · 0.95
shardMethod · 0.95
shard_likeMethod · 0.95
test_same_devMethod · 0.95
test_double_fromMethod · 0.95
test_assign_copyMethod · 0.95
test_simple_setitemMethod · 0.95
test_simple_readMethod · 0.95
test_convert_to_cpuMethod · 0.95
test_forward_match_mpMethod · 0.95

Calls 4

is_param_Method · 0.95
canonicalize_deviceFunction · 0.90
TensorClass · 0.85
copy_to_deviceMethod · 0.80

Tested by 10

test_same_devMethod · 0.76
test_double_fromMethod · 0.76
test_assign_copyMethod · 0.76
test_simple_setitemMethod · 0.76
test_simple_readMethod · 0.76
test_convert_to_cpuMethod · 0.76
test_forward_match_mpMethod · 0.76
test_forward_match_dpMethod · 0.76