#!/usr/bin/env python3 """Debug E4B inference using MLX to compare with Swift Metal.""" import mlx.core as mx import numpy as np import json from pathlib import Path import struct MODEL_PATH = Path("/Users/accusys/MarkBase12B/models/E4B-MarkBase") def load_config(): with open(MODEL_PATH / "config.json") as f: return json.load(f) def bf16_to_f32_bytes(bf16_data): """Convert raw BF16 bytes to float32 numpy array.""" bf16_uint = np.frombuffer(bf16_data, dtype=np.uint16) f32_uint = bf16_uint.astype(np.uint32) << 16 return f32_uint.view(np.float32) def load_safetensors_raw(): """Load safetensors file and return raw data + metadata.""" model_file = MODEL_PATH / "model.safetensors" with open(model_file, 'rb') as f: header_size = struct.unpack('