#!/usr/bin/env python3 """Reference-only check of Vision-Exp weights and the official PyTorch image graph. Production code never invokes this script. Inputs are the pinned DS4 source and DeepSeek source revisions recorded in docs/issue100-vision, and native dumps from the ignored issue100_encoder_real_weights test. """ import argparse import importlib.util import json from pathlib import Path import sys from types import SimpleNamespace import numpy as np import torch p = argparse.ArgumentParser() p.add_argument('--ds4-source', type=Path, required=True) p.add_argument('--official-source', type=Path, required=True) p.add_argument('--artifacts', type=Path, required=True) p.add_argument('--native', type=Path, required=True) p.add_argument('--image', type=Path, required=True) p.add_argument('--device', default='mps') a = p.parse_args() parser_path = a.ds4_source / 'gguf-tools/mixed/splice_mixed_expert_layers_gguf.py' spec = importlib.util.spec_from_file_location('ds4_gguf', parser_path) gguf = importlib.util.module_from_spec(spec) sys.modules[spec.name] = gguf spec.loader.exec_module(gguf) sys.path.insert(0, str(a.official_source / 'inference')) from vision import ViT, Aligner from image_processor import load_image, build_image_block config = json.loads((a.official_source / 'config.json').read_text()) config['dim'] = config['hidden_size'] args = SimpleNamespace(**config) file = a.artifacts / 'DeepSeek-V4-Flash-Vision-Encoder.gguf' gguf.GGML_QUANT_SIZES[30] = (1, 2, "BF16") # GGML BF16, raw source weights. info = gguf.parse_gguf(file) torch.set_default_dtype(torch.bfloat16) torch.set_default_device(a.device) vit, aligner = ViT(args), Aligner(args) with file.open('rb') as f: def state(prefix): result = {} for name, t in info.tensor_by_name.items(): if not name.startswith(prefix): continue assert t.ggml_type == 30, (name, t.ggml_type) f.seek(t.data_offset) values = np.frombuffer(f.read(t.n_bytes), dtype=' .99, result print(json.dumps(result), flush=True)