Download component.py from gatilin/tokenflow_clipb_32k_visual_codec: direct link, hf CLI and curl.
- Browser
- Download file 599 Bytes
-
https://huggingface.co/gatilin/tokenflow_clipb_32k_visual_codec/resolve/main/component.py
- Command line
-
hf download hf://gatilin/tokenflow_clipb_32k_visual_codec/component.py
-
curl -L -o component.py https://huggingface.co/gatilin/tokenflow_clipb_32k_visual_codec/resolve/main/component.py
599 Bytes
| from pathlib import Path | |
| import torch | |
| from accelerate import init_empty_weights | |
| from safetensors.torch import load_file | |
| from native.vq_model import TokenFlow, ModelArgs | |
| def load_model(path=None, dtype=torch.float32, device='cpu'): | |
| root = Path(path or Path(__file__).parent) | |
| args = ModelArgs(codebook_size=32768, teacher='clipb_224', enhanced_decoder=True, infer_interpolate=True) | |
| with init_empty_weights(): | |
| model = TokenFlow(args) | |
| model.load_state_dict(load_file(root / 'model.safetensors'), strict=True, assign=True) | |
| return model.to(device=device, dtype=dtype).eval() | |