Download experiments/shared/src/utils/parameter_count.py from cccat6/FlowMo-WM: direct link, hf CLI and curl.
- Browser
- Download file 664 Bytes
-
https://huggingface.co/cccat6/FlowMo-WM/resolve/dd3258b67d055ee2ef6d024c562dab46d4d25f1a/experiments/shared/src/utils/parameter_count.py
- Command line
-
hf download hf://cccat6/FlowMo-WM@dd3258b67d055ee2ef6d024c562dab46d4d25f1a/experiments/shared/src/utils/parameter_count.py
-
curl -L -o parameter_count.py https://huggingface.co/cccat6/FlowMo-WM/resolve/dd3258b67d055ee2ef6d024c562dab46d4d25f1a/experiments/shared/src/utils/parameter_count.py
664 Bytes
| """Parameter counting utilities.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from torch import nn | |
| def parameter_count_by_component(model: nn.Module) -> dict[str, int]: | |
| counts = {name: sum(p.numel() for p in module.parameters()) for name, module in model.named_children()} | |
| counts["total"] = sum(p.numel() for p in model.parameters()) | |
| return counts | |
| def save_parameter_count(model: nn.Module, path: str | Path) -> dict[str, int]: | |
| counts = parameter_count_by_component(model) | |
| out = Path(path) | |
| out.parent.mkdir(parents=True, exist_ok=True) | |
| out.write_text(json.dumps(counts, indent=2)) | |
| return counts | |