Spaces:
Running on Zero
Running on Zero
Download src/misc/nn_module_tools.py from timfromhcs/AnySplat: direct link, hf CLI and curl.
- Browser
- Download file 565 Bytes
-
https://huggingface.co/spaces/timfromhcs/AnySplat/resolve/main/src/misc/nn_module_tools.py
- Command line
-
hf download hf://spaces/timfromhcs/AnySplat/src/misc/nn_module_tools.py
-
curl -L -o nn_module_tools.py https://huggingface.co/spaces/timfromhcs/AnySplat/resolve/main/src/misc/nn_module_tools.py
565 Bytes
| from torch import nn | |
| def convert_to_buffer(module: nn.Module, persistent: bool = True): | |
| # Recurse over child modules. | |
| for name, child in list(module.named_children()): | |
| convert_to_buffer(child, persistent) | |
| # Also re-save buffers to change persistence. | |
| for name, parameter_or_buffer in ( | |
| *module.named_parameters(recurse=False), | |
| *module.named_buffers(recurse=False), | |
| ): | |
| value = parameter_or_buffer.detach().clone() | |
| delattr(module, name) | |
| module.register_buffer(name, value, persistent=persistent) | |