Change dump output format to dict with value and metadata (#18879)
This commit is contained in:
@@ -280,6 +280,9 @@ def _load_object(path):
|
||||
print(f"Skip load {path} since error {e}")
|
||||
return None
|
||||
|
||||
if isinstance(x, dict) and "value" in x:
|
||||
x = x["value"]
|
||||
|
||||
if not isinstance(x, torch.Tensor):
|
||||
print(f"Skip load {path} since {type(x)=} is not a Tensor ({x=})")
|
||||
return None
|
||||
|
||||
@@ -34,6 +34,8 @@ class DumpLoader:
|
||||
|
||||
path = self._directory / row["filename"]
|
||||
output = torch.load(path, weights_only=False)
|
||||
if isinstance(output, dict) and "value" in output:
|
||||
output = output["value"]
|
||||
|
||||
print(
|
||||
f"[DumpLoader] load from {path=} (query: {name=} {kwargs=}, output: {type(output)})"
|
||||
|
||||
@@ -164,7 +164,11 @@ class _Dumper:
|
||||
|
||||
if self._enable_write_file and save:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
_torch_save(value, str(path))
|
||||
output_data = {
|
||||
"value": value.data if isinstance(value, torch.nn.Parameter) else value,
|
||||
"meta": full_kwargs,
|
||||
}
|
||||
_torch_save(output_data, str(path))
|
||||
|
||||
|
||||
def _torch_save(value, path: str):
|
||||
|
||||
Reference in New Issue
Block a user