#!/usr/bin/env python3 """ Build a tiny slice of LiquidAI/d1-3B (lfm2-d1 decision model, LFM2-VL based) for testing. Output is gibberish, only the shapes and code paths are real. Adapted from the slice-model skill of llama.cpp (skills/slice-model): tensors are fetched with HTTP range requests and config.json is patched to match, then convert_hf_to_gguf.py does the conversion. It keeps a few layers and also narrows the widths: the 128000 x 2048 token embedding alone would be far too big, text hidden 64 keeps the Q4_0 GGUF under 10 MB. usage: slice_d1_3b.py """ import json, re, struct, sys from concurrent.futures import ThreadPoolExecutor from pathlib import Path import requests import torch from huggingface_hub import hf_hub_url from safetensors.torch import save_file REPO = 'LiquidAI/d1-3B' AUX = ['tokenizer.json', 'tokenizer_config.json', 'chat_template.jinja', 'processor_config.json', 'LICENSE'] E, H, KV, FF = 64, 1, 1, 256 # text: hidden, heads, kv heads, ffn. head_dim stays 64 (hidden / heads) V, VH, VFF, VP = 144, 2, 288, 256 # vision: hidden, heads (head_dim stays 72), ffn, projector hidden size TEXT_LAYERS = [0, 2, 3, 5] # conv, full attn, conv, full attn VISION_LAYERS = [0, 1, 2] # 3 layers: the converter maps multi_modal_projector.linear_{bid} by block id, linear_2 needs a block count > 2 DTYPES = {'BF16': torch.bfloat16, 'F32': torch.float32, 'F16': torch.float16} def read_header(url): def rng(a, b): r = requests.get(url, headers={'Range': f'bytes={a}-{b}'}, timeout=120) r.raise_for_status() return r.content n = struct.unpack('