Download code/bifurcation/models/_common.py from coarse-grained-forecasting-benchmark/forecasting-models: direct link, hf CLI and curl.
- Browser
- Download file 464 Bytes
-
https://huggingface.co/coarse-grained-forecasting-benchmark/forecasting-models/resolve/main/code/bifurcation/models/_common.py
- Command line
-
hf download hf://coarse-grained-forecasting-benchmark/forecasting-models/code/bifurcation/models/_common.py
-
curl -L -o _common.py https://huggingface.co/coarse-grained-forecasting-benchmark/forecasting-models/resolve/main/code/bifurcation/models/_common.py
464 Bytes
| """Shared helpers for backbones.""" | |
| from __future__ import annotations | |
| import torch | |
| def _pack_scalar(s: torch.Tensor, B: int) -> torch.Tensor: | |
| """Normalize a scalar / per-batch scalar to shape (B, 1).""" | |
| if s.ndim == 0 or (s.ndim == 1 and s.numel() == 1): | |
| return s.view(1, 1).expand(B, 1) | |
| return s.reshape(B, 1) | |
| def count_parameters(model: torch.nn.Module) -> int: | |
| return sum(p.numel() for p in model.parameters() if p.requires_grad) | |