Download component.py from gatilin/nld-uni-packed-image-codec: direct link, hf CLI and curl.
- Browser
- Download file 787 Bytes
-
https://huggingface.co/gatilin/nld-uni-packed-image-codec/resolve/main/component.py
- Command line
-
hf download hf://gatilin/nld-uni-packed-image-codec/component.py
-
curl -L -o component.py https://huggingface.co/gatilin/nld-uni-packed-image-codec/resolve/main/component.py
787 Bytes
| """Load NLD-Uni's packed image-token bridge with its original implementation.""" | |
| from pathlib import Path | |
| import importlib.util | |
| from safetensors.torch import load_file | |
| def load_model(root): | |
| root = Path(root).resolve() | |
| spec = importlib.util.spec_from_file_location('nld_uni_packed_bridge', root / 'bridge.py') | |
| module = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(module) | |
| model = module.PackedLinearImageCodec(4096, norm_eps=1e-6, device='meta') | |
| state = load_file(str(root / 'model.safetensors'), device='cpu') | |
| prefix = 'encoder.packed_image_codec.' | |
| assert all(key.startswith(prefix) for key in state) | |
| model.load_state_dict({key[len(prefix):]: value for key, value in state.items()}, strict=True, assign=True) | |
| return model.eval() | |