MCPcopy
hub / github.com/hpcaitech/ColossalAI / to

Method to

colossalai/lazy/lazy_init.py:361–382  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

359 return wrap(o)
360
361 def to(self, *args, **kwargs) -> torch.Tensor:
362 if self._materialized_data is not None:
363 return LazyTensor(lambda: None, concrete_data=self._materialized_data.to(*args, **kwargs))
364
365 device = None
366
367 def replace(x):
368 nonlocal device
369 if isinstance(x, (str, int, torch.device)) and not isinstance(x, bool):
370 device = x
371 return torch.device("meta")
372 return x
373
374 meta_data = self._meta_data.to(*tree_map(replace, args), **tree_map(replace, kwargs))
375
376 if meta_data is self._meta_data and device == self.device:
377 return self
378
379 def factory_fn(t: torch.Tensor, **kw):
380 return t.to(*args, **kwargs)
381
382 return LazyTensor(factory_fn, self, meta_data=meta_data, device=device)
383
384 def cpu(self, memory_format: torch.memory_format = torch.preserve_format):
385 return self.to(device=torch.device("cpu"), memory_format=memory_format)

Callers 15

cpuMethod · 0.95
cudaMethod · 0.95
initialize_device_meshFunction · 0.45
_get_arg_valueMethod · 0.45
memory_optimizeFunction · 0.45
_cast_floatFunction · 0.45
_object_to_tensorFunction · 0.45
_init_chunksMethod · 0.45
_cast_buffersMethod · 0.45
get_static_torch_modelFunction · 0.45

Calls 1

LazyTensorClass · 0.85

Tested by 15

run_dist_lamb_basicFunction · 0.36
run_dist_lamb_fwd_bwdFunction · 0.36
exam_dist_came_baseFunction · 0.36
check_adam_kernelFunction · 0.36
run_dist_galore_basicFunction · 0.36
run_dist_galore_fwd_bwdFunction · 0.36
exam_dist_adafactor_baseFunction · 0.36
exam_dist_adafactor_zeroFunction · 0.36
test_adam_optim_on_bertFunction · 0.36
test_coloproxyFunction · 0.36
test_linear_moduleFunction · 0.36