This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
NunzeandClaude Opus 5.5 b0bcb74c5b core/mm: GLM-5.3's processor -- a canvas within a token budget, padded rather than stretched
A fourth processor family beside Qwen-VL, Gemma 4 and LFM2-VL, chosen by vision_config.model_type
glm5_next_vision, as transformers' Glm5NextImageProcessor (torchvision backend) computes it:

- The canvas: both sides rounded up to patch * merge (28), grown by the area ratio under
  min_image_tokens, and fitted by the reference's binary search over the picture's height past
  max_image_tokens, a token being two frames of 28 x 28 pixels.
- The picture keeps its aspect ratio, is never enlarged while it reaches the floor, is resized
  with torchvision's fixed-point bicubic only when its size changes, and sits in the top left of a
  canvas of zero bytes, which the normalisation turns into each channel's -mean / std as it does
  the reference's padding. Patches as Qwen-VL's (merge-block order, (channel, frame, y, x), the
  picture in both frames, CLIP's mean and deviation from processor_config.json).
- <|begin_of_image|>, one <|image|> a token, <|end_of_image|>; the tokens rotate at their
  positions (the language model has no rotary). Pictures only.

The budget is in tokens and comes from processor.image_processor.{min,max}_image_tokens; one
encoder pass bounds it, so it is lowered to max_patches / merge^2, as a Qwen-VL pixel band is
(4096 tokens at --mm-max-patches auto, the checkpoint's 8000 at 32000). --image-tokens sets the
ceiling; the pixel-band and video flags, a request's image_tokens and a video are refused by name.

tests/mkglm5golden.py writes glm5_golden.h from Glm5NextProcessor; mm_test checks canvases over a
grid of sizes and both budgets, and whole pictures (padded only, grown under the floor, shrunk to
a budget) patch for patch and token for token, all bit-exact, and the processor read from a
container's keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 11:06:34 +02:00

74 lines
4.2 KiB
C++

/* glm5_golden.h -- GENERATED by mkglm5golden.py from transformers 5.21.0.dev0; do not edit. */
#pragma once
#include <cstdint>
static const int32_t kGlm5Patch = 14, kGlm5Merge = 2, kGlm5Temporal = 2, kGlm5MinTok = 16, kGlm5MaxTok = 8000;
static const int32_t kGlm5Image = 154854, kGlm5Start = 154830, kGlm5End = 154831;
static const float kGlm5Mean[3] = { 0.48145466f, 0.4578275f, 0.40821073f }, kGlm5Std[3] = { 0.26862954f, 0.26130258f, 0.27577711f };
struct GoldGlm5Size { int64_t h, w; int32_t budget; int64_t oh, ow, patches; };
static const GoldGlm5Size kGoldGlm5Size[] = {
{ 1, 1, 8000, 112, 112, 64 },
{ 1, 1, 4096, 112, 112, 64 },
{ 100, 100, 8000, 112, 112, 64 },
{ 100, 100, 4096, 112, 112, 64 },
{ 61, 97, 8000, 112, 168, 96 },
{ 61, 97, 4096, 112, 168, 96 },
{ 3, 4000, 8000, 28, 4004, 572 },
{ 3, 4000, 4096, 28, 4004, 572 },
{ 448, 448, 8000, 448, 448, 1024 },
{ 448, 448, 4096, 448, 448, 1024 },
{ 300, 500, 8000, 308, 504, 792 },
{ 300, 500, 4096, 308, 504, 792 },
{ 768, 1024, 8000, 784, 1036, 4144 },
{ 768, 1024, 4096, 784, 1036, 4144 },
{ 1080, 1920, 8000, 1092, 1932, 10764 },
{ 1080, 1920, 4096, 1092, 1932, 10764 },
{ 2048, 2048, 8000, 2072, 2072, 21904 },
{ 2048, 2048, 4096, 1792, 1792, 16384 },
{ 3000, 4000, 8000, 2156, 2884, 31724 },
{ 3000, 4000, 4096, 1540, 2072, 16280 },
{ 4000, 3000, 8000, 2884, 2156, 31724 },
{ 4000, 3000, 4096, 2072, 1540, 16280 },
{ 20, 1500, 8000, 28, 1512, 216 },
{ 20, 1500, 4096, 28, 1512, 216 },
{ 1500, 20, 8000, 1512, 28, 216 },
{ 1500, 20, 4096, 1512, 28, 216 },
{ 111, 113, 8000, 112, 140, 80 },
{ 111, 113, 4096, 112, 140, 80 },
{ 112, 112, 8000, 112, 112, 64 },
{ 112, 112, 4096, 112, 112, 64 },
{ 113, 111, 8000, 140, 112, 80 },
{ 113, 111, 4096, 140, 112, 80 },
{ 2300, 2900, 8000, 2240, 2800, 32000 },
{ 2300, 2900, 4096, 1596, 1988, 16188 },
{ 7000, 120, 8000, 7000, 140, 5000 },
{ 7000, 120, 4096, 7000, 140, 5000 },
{ 120, 7000, 8000, 140, 7000, 5000 },
{ 120, 7000, 4096, 140, 7000, 5000 },
{ 5000, 5000, 8000, 2492, 2492, 31684 },
{ 5000, 5000, 4096, 1792, 1792, 16384 },
{ 12000, 9000, 8000, 2884, 2156, 31724 },
{ 12000, 9000, 4096, 2072, 1540, 16280 },
{ 2160, 3840, 8000, 1876, 3332, 31892 },
{ 2160, 3840, 4096, 1344, 2380, 16320 },
{ 1, 30000, 8000, 28, 30016, 4288 },
{ 1, 30000, 4096, 28, 30016, 4288 },
{ 900, 1400, 8000, 924, 1400, 6600 },
{ 900, 1400, 4096, 924, 1400, 6600 },
};
struct GoldGlm5Pic { int32_t f, h, w, budget, grid_h, grid_w; uint64_t fnv; int32_t n_ids; uint64_t ids_fnv; uint16_t head[8]; };
static const GoldGlm5Pic kGoldGlm5Pics[] = {
{ 0, 448, 448, 8000, 32, 32, 0xd1a1afd8f20ac789ull, 258, 0x72139e1c3f39bf1cull, { 0xbf1c, 0xbfc0, 0x3e0a, 0x3fc6, 0xbf7d, 0x3e64, 0x3f8e, 0x3f87 } },
{ 1, 300, 500, 8000, 22, 36, 0x7be72496cfec045dull, 200, 0x255584700075589cull, { 0x3f0b, 0xbe30, 0xbf91, 0x3fdb, 0xbfe2, 0xbe6c, 0x3f4b, 0x3fa7 } },
{ 2, 61, 97, 8000, 8, 12, 0xfedf63278fd84bf1ull, 26, 0x257747e49c4ee91cull, { 0x3ff1, 0x3fce, 0x3f96, 0x3fa9, 0x3fb2, 0x3f4e, 0x3f13, 0x3f47 } },
{ 3, 3, 400, 8000, 2, 94, 0x26cc3ab47053bc9dull, 49, 0xfbf168ec084616acull, { 0xbfe5, 0xbfda, 0xbf5f, 0x3ef8, 0x3fe3, 0x3ff7, 0x3fdf, 0x3f96 } },
{ 4, 20, 1500, 8000, 2, 108, 0x2fd52c52ec4a00a9ull, 56, 0x47537633a0505c9cull, { 0x3f94, 0xbeb2, 0xbf3e, 0x3e64, 0xbfc9, 0xbed0, 0x3f5a, 0xbf41 } },
{ 5, 900, 1400, 256, 26, 38, 0x398290b8912d19d9ull, 249, 0x355dfb37a793d4acull, { 0x3f34, 0xbec1, 0xbf11, 0xbe12, 0xbe85, 0x3d9c, 0x3c93, 0x3f29 } },
{ 6, 1200, 1700, 4096, 86, 122, 0x5fd09cd1af13ba41ull, 2625, 0xf9b8b842d63572acull, { 0xbf8f, 0x3fa5, 0xbf6b, 0x3f61, 0x3fac, 0xbf67, 0xbf18, 0x3df6 } },
{ 7, 2300, 2900, 8000, 160, 200, 0x267b44f24a266119ull, 8002, 0x41e705bec95caf1cull, { 0xbf3a, 0x3fc1, 0xbe94, 0xbfc0, 0xbfa0, 0xbe94, 0xbf7a, 0xbf9b } },
{ 8, 1, 1, 8000, 8, 8, 0xb8835c50fee76f25ull, 18, 0xb05a4c2103cd9b1cull, { 0xbfb1, 0xbfb1, 0xbfb1, 0xbfb1, 0xbfb1, 0xbfb1, 0xbfb1, 0xbfb1 } },
{ 9, 113, 111, 8000, 10, 8, 0x4ae29fe59e7b4e15ull, 22, 0xd734c8e25ac1621cull, { 0xbfba, 0x3fe4, 0xbf11, 0xbf33, 0x3ed3, 0x3f43, 0xbfc9, 0xbfbc } },
};