Download runtime/tools/split_modalities.py from SupersonicLabs/Julia-2-Flash: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/SupersonicLabs/Julia-2-Flash/resolve/main/runtime/tools/split_modalities.py
- Command line
-
hf download hf://SupersonicLabs/Julia-2-Flash/runtime/tools/split_modalities.py
-
curl -L -o split_modalities.py https://huggingface.co/SupersonicLabs/Julia-2-Flash/resolve/main/runtime/tools/split_modalities.py
1.09 kB
| """Split one variant's model.safetensors into text / image / audio files, so a text-only user downloads and opens | |
| only the decision trunk. The runtime reads the split files when model.safetensors is absent. | |
| python -m tools.split_modalities <variant dir> <out dir> | |
| """ | |
| import sys | |
| from pathlib import Path | |
| from safetensors import safe_open | |
| from safetensors.torch import save_file | |
| def part(key): | |
| if key.startswith("trunk.visual."): | |
| return "image" | |
| if key.startswith("audio."): | |
| return "audio" | |
| return "text" | |
| def main(): | |
| src, dst = Path(sys.argv[1]), Path(sys.argv[2]) | |
| f = safe_open(str(src / "model.safetensors"), "pt") | |
| meta = f.metadata() or {} | |
| parts = {} | |
| for k in f.keys(): | |
| parts.setdefault(part(k), {})[k] = f.get_tensor(k).contiguous() | |
| dst.mkdir(parents=True, exist_ok=True) | |
| for name, tensors in parts.items(): | |
| save_file(tensors, str(dst / f"{name}.safetensors"), metadata=meta) | |
| print(name, sum(t.numel() * t.element_size() for t in tensors.values()) / 1e9, "GB") | |
| if __name__ == "__main__": | |
| main() | |