#!/usr/bin/env python3 """ Build a tiny slice of LiquidAI/d1-2B (lfm3-d1 decision model) 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. The stock script only drops layers, which cannot go below the 128000 x 2048 token embedding, so this one also narrows the hidden sizes (text hidden 64 keeps the Q4_0 GGUF under 10 MB). Adapted from slice_d1omni.py of ggml-org-dev/tiny-d1-Omni-2B-for-testing. d1-2B has the LFM3-VL weights (no audio encoder, no depthformer). usage: slice_d1.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-2B' AUX = ['tokenizer.json', 'tokenizer_config.json', 'chat_template.jinja', 'processor_config.json', 'calibration.json', 'LICENSE'] E, H, KV, FF = 64, 2, 1, 256 # text: hidden, heads, kv heads, ffn. head_dim stays 128 V, VH, VKV, VFF, VP = 128, 2, 1, 256, 256 # vision, head_dim stays 64, VP is the projector hidden size TEXT_LAYERS = [0, 2, 3, 4] # conv, full attn, conv, sliding attn VISION_LAYERS = [0, 2] # conv, full attn 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('