"""Export local HF Falcon-H1 safetensors into exact-name f32 FH1W tensor pack. Dependencies: pip install safetensors torch huggingface_hub Example: python tools/export.py --repo tiiuae/Falcon-H1-0.5B-Instruct --output falcon-h1.f32pack The 0.5B model is ~2 GB in float32; this is CPU reference, not a GPU converter. """ import argparse import struct from pathlib import Path from huggingface_hub import snapshot_download from safetensors import safe_open def convert(model_dir: Path, output: Path): paths = sorted(model_dir.glob("*.safetensors")) if not paths: raise ValueError("No safetensors files in selected model directory") # Include only model tensors; do not include unrelated training checkpoint tensors. entries = [] for path in paths: with safe_open(str(path), framework="pt", device="cpu") as sf: for name in sf.keys(): if name.startswith(("model.", "lm_head.")): entries.append((path, name)) if len(entries) > 50000: raise ValueError("Too many checkpoint tensors") output.parent.mkdir(parents=True, exist_ok=True) with output.open("wb") as f: f.write(b"FH1W") f.write(struct.pack("