mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-10 21:40:02 +00:00
[legacy] move communication and nn to legacy and refactor logger (#4671)
* [legacy] move communication to legacy (#4640) * [legacy] refactor logger and clean up legacy codes (#4654) * [legacy] make logger independent to gpc * [legacy] make optim independent to registry * [legacy] move test engine to legacy * [legacy] move nn to legacy (#4656) * [legacy] move nn to legacy * [checkpointio] fix save hf config * [test] remove useledd rpc pp test * [legacy] fix nn init * [example] skip tutorial hybriad parallel example * [devops] test doc check * [devops] test doc check
This commit is contained in:
@@ -470,3 +470,22 @@ def disposable(func: Callable) -> Callable:
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def free_storage(data: torch.Tensor) -> None:
|
||||
"""Free underlying storage of a Tensor."""
|
||||
if data.storage().size() > 0:
|
||||
# Since we're modifying the Tensor's Storage directly, make sure the Tensor
|
||||
# is the sole occupant of the Storage.
|
||||
assert data.storage_offset() == 0
|
||||
data.storage().resize_(0)
|
||||
|
||||
|
||||
def _cast_float(args, dtype: torch.dtype):
|
||||
if isinstance(args, torch.Tensor) and torch.is_floating_point(args):
|
||||
args = args.to(dtype)
|
||||
elif isinstance(args, (list, tuple)):
|
||||
args = type(args)(_cast_float(t, dtype) for t in args)
|
||||
elif isinstance(args, dict):
|
||||
args = {k: _cast_float(v, dtype) for k, v in args.items()}
|
||||
return args
|
||||
|
Reference in New Issue
Block a user