Change dump output format to dict with value and metadata (#18879)

This commit is contained in:
fzyzcjy
2026-02-16 13:30:47 +08:00
committed by GitHub
parent 02816abc0d
commit 949792d0c6
4 changed files with 70 additions and 3 deletions

View File

@@ -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

View File

@@ -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)})"

View File

@@ -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):