Repository navigation
Description
Summary
Add GLM-OCR support to mlxcel. GLM-OCR is a compact document-OCR VLM: a 24-block ViT vision tower (packed cu_seqlens attention, 2D rotary, Conv2d spatial downsample, SwiGLU patch merger) feeding a 16-layer GLM-4-style text decoder driven by full-width even/odd MRoPE. Checkpoints ship config.json with model_type: "glm_ocr" (architecture GlmOcrForConditionalGeneration); mlxcel has no arm for it in src/models/detection.rs, so loading fails with "Unsupported model type".
The model is a close sibling of the in-tree GLM-4V stack (src/models/glm4v.rs, src/vision/glm4v.rs, src/vision/encoders/glm4v.rs), so most of the port is a variant of existing code rather than new machinery. A real checkpoint is available as zai-org/GLM-OCR (bf16, single model.safetensors, 526 tensors); all config values, weight keys, and shapes below were verified against it.
Current state in mlxcel
grep -r glm_ocr src/ returns nothing. Relevant existing pieces (all paths verified):
src/models/glm4v.rs:Glm4vTextModel+Glm4vTextConfig+Glm4vMRoPE(chunked axis selector,EvenOdd/HalfSplitpairing) + per-sequence MRoPE state viacrate::models::qwen_mrope_state::MRopeState. The decoder layer (4 RMSNorms, fusedgate_up_proj) is exactly what GLM-OCR needs.src/vision/encoders/glm4v.rs:Glm4vVisionEncoderwithPatchEmbed(Conv3d as linear),VisionRotaryEmbedding+host_pos_ids+rotary_table, packed-attentionVisionBlock,Downsample(Conv2d as linear),PatchMerger. GLM-OCR reuses most of this but is not identical (see Architecture).src/vision/glm4v.rs:Glm4vModelVLM wrapper withget_input_embeddings+compute_rope_index+ theLanguageModelimpl.src/vision/processors/qwen2_vl.rs:Qwen2VLProcessor(smart resize to multiples of 28, CLIP mean/std, patch flattening). GLM-OCR uses the same scheme with different pixel bounds.src/loading/vlm_qwen.rs:load_glm4v,remap_glm4v_weights,extract_glm4v_mrope_section(already checks bothrope_scalingandrope_parameters),extract_glm4v_eos_token_ids; shared helpersqwen_vl_processor/qwen_vl_token_idslive insrc/loading/vlm.rs.src/multimodal/qwen_vl.rs:QwenVlRuntimetrait,impl_qwen_vl_runtime_loop_dispatch!macro,insert_qwen_vl_image_tokensplaceholder expansion.- Registration surfaces:
src/models/detection.rs,src/models/mod.rs(enum,ALL_MODEL_TYPES, display names,all_variants!test list),src/loaded_model.rs(enum + dispatch macro),src/loaded_model_capabilities.rs(VlmRuntimeRef::Qwen),src/loading/mod.rs,src/model_metadata.rs. - OCR precedent: PaddleOCR-VL (
src/vision/paddleocr_vl.rs,src/vision/encoders/paddleocr_vl.rs,src/vision/connectors/paddleocr_vl.rs,src/vision/processors/paddleocr_vl.rs,src/loading/vlm_paddleocr.rs,tests/paddleocr_vl_parity.rs). Useful mainly for its dual-layout conv-weight detection and its test structure; architecturally GLM-OCR is much closer to GLM-4V.
Architecture
config.json (exact keys and values from the reference checkpoint)
Top level: model_type: "glm_ocr", image_token_id: 59280, video_token_id: 59281, image_start_token_id: 59256, image_end_token_id: 59257, video_start_token_id: 59258, video_end_token_id: 59259.
text_config (model_type: "glm_ocr_text"):
| key | value |
|---|---|
vocab_size |
59392 |
hidden_size |
1536 |
intermediate_size |
4608 |
num_hidden_layers |
16 |
num_attention_heads |
16 |
num_key_value_heads |
8 |
head_dim |
128 (explicit: 16 x 128 = 2048 != hidden_size) |
attention_bias |
false |
rms_norm_eps |
1e-05 |
max_position_embeddings |
131072 |
eos_token_id |
[59246, 59253] |
pad_token_id |
59246 |
tie_word_embeddings |
false |
num_nextn_predict_layers |
1 |
rope_parameters |
{"rope_type": "default", "mrope_section": [16, 24, 24], "partial_rotary_factor": 1.0, "rope_theta": 10000} |
Config trap: the rope block is nested under rope_parameters, not rope_scaling, and there is no top-level rope_theta or partial_rotary_factor. Glm4vTextConfig today deserializes rope_scaling.mrope_section and top-level rope_theta/partial_rotary_factor with defaults 0.5 and [8, 12, 12]. Feeding this config through unchanged silently produces half-width rotary with wrong sections, which decodes garbage. The loader (or a serde alias plus extended RopeScaling fields) must lift rope_parameters.partial_rotary_factor = 1.0, rope_parameters.mrope_section = [16, 24, 24], and rope_parameters.rope_theta = 10000.
vision_config (model_type: "glm_ocr_vision"): depth: 24, hidden_size: 1024, num_heads: 16, intermediate_size: 4096, attention_bias: true, image_size: 336, patch_size: 14, out_hidden_size: 1536, rms_norm_eps: 1e-05, spatial_merge_size: 2, temporal_patch_size: 2, in_channels implicitly 3.
preprocessor_config.json: size: {shortest_edge: 12544, longest_edge: 9633792} (min/max pixels), patch_size: 14, temporal_patch_size: 2, merge_size: 2, image_mean: [0.48145466, 0.4578275, 0.40821073], image_std: [0.26862954, 0.26130258, 0.27577711], do_rescale: true.
Vision tower (24 blocks, hidden 1024, 16 heads, head_dim 64)
Patch embedding: a 3D convolution with kernel == stride == (kT=2, kH=14, kW=14), 3 -> 1024 channels, with bias. Because kernel == stride it degenerates to a linear layer over each flattened patch of 3 x 2 x 14 x 14 = 1176 features. The in-tree PatchEmbed in src/vision/encoders/glm4v.rs already evaluates it as a matmul; only the weight permutation differs by source layout (see Weight loading).
Per-block, operating on packed tokens (total_patches, 1024) with no batch axis:
norm1: RMSNorm(1024, eps 1e-5). The in-tree glm4vVisionBlockhardcodes eps 1e-6; GLM-OCR must use the config value 1e-5.- Attention: fused
qkvlinear 1024 -> 3072 with bias, output reshaped to(total, 3, n_heads=16, head_dim=64)and split along axis 1 into q, k, v each(total, 16, 64).- q_norm / k_norm (new vs the in-tree glm4v block): per-head RMSNorm over the last axis (
head_dim64, eps 1e-5, weight shape(64,)) applied to q and k before rotary. - 2D rotary: for token at patch grid position
(h_pos, w_pos), the angle vector has 32 entries:theta = [h_pos * f_0..f_15, w_pos * f_0..f_15]withf_i = 10000^(-i/16). cos/sin are formed by duplicating theta along the last axis to 64 entries (concat of theta with itself at axis -1), then rotate-half application over the full 64 dims:x_rot = x * cos + rotate_half(x) * sin, whererotate_halfsplits the 64-dim last axis at index 32 into(x1, x2)and returnsconcat(-x2, x1, axis=-1). This matches the in-treeVisionRotaryEmbedding+rotary_table+apply_rotary_pos_emb_visionscheme insrc/vision/encoders/glm4v.rs, reusable as-is. - Packed attention: q/k/v transposed to
(1, n_heads, total, head_dim); scaled dot-product attention (scale 64^-0.5, no mask) is run per image segment by slicing axis 2 at thecu_seqlensboundaries (one segment per frame,h * wpatches each). Output transposed back and reshaped to(total, 1024), thenprojlinear 1024 -> 1024 with bias.
- q_norm / k_norm (new vs the in-tree glm4v block): per-head RMSNorm over the last axis (
- Residual add,
norm2RMSNorm(1024, eps 1e-5), MLP: SwiGLU withgate_proj/up_proj1024 -> 4096 anddown_proj4096 -> 1024, all with bias (glm4v vision MLP is bias-free),down(silu(gate(x)) * up(x)), residual add.
Absent vs the in-tree glm4v encoder (the checkpoint has no such tensors, do not port them): the learned embeddings.position_embedding with bilinear/grid resampling, and post_conv_layernorm. Patch embeddings go straight into block 0; position information comes only from the 2D rotary.
After the blocks:
post_layernorm: RMSNorm(1024, eps 1e-5) on(total, 1024).- Downsample: reshape
(total, 1024)->(total/4, 2, 2, 1024)grouping each spatial-merge window, then a Conv2d with kernel == stride == 2, 1024 -> 1536 channels, with bias, i.e. a linear over each flattened(2, 2, 1024)block ->(total/4, 1536). The block flatten order is (kH, kW, channels); the weight must be flattened in the same order (see Weight loading). - Merger (
merger.*):proj1536 -> 1536 (no bias) ->post_projection_normLayerNorm(1536, weight + bias, eps 1e-5) -> GELU -> SwiGLU withgate_proj/up_proj1536 -> 4608 anddown_proj4608 -> 1536 (all no bias). Output(merged_tokens, 1536)lands directly in the text hidden size; there is no separate connector module (same as glm4v, the projection lives inside the tower).
Merged token count per image: t * (h/2) * (w/2) with grid dims in patch units and t = 1 for still images.
Text decoder (16 layers, GLM-4 style)
Same block structure as Glm4vTextModel in src/models/glm4v.rs (reusable as-is):
- Four RMSNorms per layer (
input_layernorm,post_self_attn_layernormapplied to the attention output before the residual add,post_attention_layernormbefore the MLP,post_mlp_layernormapplied to the MLP output before the residual add), all(1536,), eps 1e-5. - Attention with decoupled head width:
q_proj1536 -> 2048 (16 heads x 128),k_proj/v_proj1536 -> 1024 (8 KV heads x 128, GQA 2:1),o_proj2048 -> 1536, no biases, scale 128^-0.5. Shapes per step: input(batch, seq, 1536), q reshaped to(batch, seq, 16, 128)then transposed to(batch, 16, seq, 128)(axes[0, 2, 1, 3]), causal mask, KV cache as usual. - MLP: fused
gate_up_proj1536 -> 9216, split at axis -1 into gate and up (4608 each),down_proj(silu(gate) * up)4608 -> 1536. - Final
normRMSNorm then untiedlm_head1536 -> 59392.
MRoPE (the one text-side formula difference from glm4v): rotary covers the full head_dim 128 (partial_rotary_factor 1.0, so rope_dims = 128, 64 frequency pairs; glm4v rotates only 64 dims). mrope_section = [16, 24, 24] sums to 64: pair index j takes the Temporal position axis for j < 16, Height for 16 <= j < 40, Width for 40 <= j < 64. Angle theta_j = pos[axis(j)] * 10000^(-j/64); pairing is even/odd (GPT-J style): dims (2j, 2j+1) rotate together, cos/sin interleave-repeated. This is exactly Glm4vMRoPE::new(10000.0, 128, &[16, 24, 24], Glm4vRopePairing::EvenOdd); no new rotary code is needed, only correct config plumbing.
3D position ids for mixed text+image sequences (shape (3, batch, seq), axes T/H/W):
- Text runs: all three axes share the same scalar position, incrementing by 1 per token.
- An image run of
llm_h * llm_wmerged tokens (llm_h = h/2,llm_w = w/2): T is constant at the run's start position; H isstart + rowwhere row runs 0..llm_h, each value repeatedllm_wtimes; W isstart + coltiledllm_htimes. After the image, the text position advances bymax(llm_h, llm_w).
For still images (t = 1) this is numerically identical to Glm4vModel::compute_rope_index in src/vision/glm4v.rs, which can be reused unchanged. Video position math differs (per-frame grouping with temporal merging) and is out of scope.
Processor and placeholder expansion
- Smart resize: round height and width to the nearest multiple of
factor = patch_size * merge_size = 28, then rescale bysqrtso thatt_bar * h_bar * w_barstays within[12544, 9633792]pixels (note the temporal factor participates in the bound). Grid per image:(t=1, h = resized_h/14, w = resized_w/14)in patch units. - Normalize:
(pixel/255 - mean) / stdwith the CLIP values above. - Native
pixel_valueslayout in the checkpoint's processing convention:(t * h * w, 1176)where each row flattens one patch in (channels, temporal, patch_h, patch_w) order and rows are ordered merge-window-major:(t, h/2, w/2, 2, 2), i.e. the four patches of each 2x2 merge window are consecutive. A still image is duplicated totemporal_patch_size = 2identical frames. - The in-tree
Qwen2VLProcessoremits(total * temporal_patch_size, 588)rows (per-row flatten (channels, patch_h, patch_w), two consecutive temporal rows per patch) and the glm4v-stylePatchEmbedregroups row pairs into 1176-feature patches; that pairing is fine. Consistency requirement: whatever row order the processor emits, the vision rotary position ids (host_pos_ids), thecu_seqlenssegmentation, the downsample's(total/4, 2, 2, 1024)window grouping, and the text-side merged-token order must all assume the same order.host_pos_idsand the downsample insrc/vision/encoders/glm4v.rsassume merge-window order whileQwen2VLProcessor::preprocess_with_gridemits plain raster order (row-major over(py, px)); verify and fix this alignment for the GLM-OCR path during parity testing, using a spatially asymmetric test image (for OCR, spatial scrambling directly destroys output quality). - Reuse
Qwen2VLProcessorwithmin_pixels = 12544andmax_pixels = 9633792(the struct fields are public; the defaults 3136 / 12845056 do not match). The CLIP mean/std defaults already match. - Placeholder expansion: the chat template renders exactly one
<|image|>(id 59280) per image, framed by<|begin_of_image|>(59256) /<|end_of_image|>(59257). The runtime must expand each single placeholder tot * (h/2) * (w/2)copies;insert_qwen_vl_image_tokensinsrc/multimodal/qwen_vl.rs(Expand case) already does this. Note the config key naming: GLM-OCR shipsimage_start_token_id, notvision_start_token_id, soqwen_vl_token_idsinsrc/loading/vlm.rswill not pick it up without a tweak; pass 59256 as the default or read the GLM-OCR key.
Prompt format
Chat template (ships as chat_template.jinja in the checkpoint): [gMASK]<sop> prefix, roles <|system|> / <|user|> / <|assistant|>, image content rendered as <|begin_of_image|><|image|><|end_of_image|>. The generation prompt ends with <|assistant|>, and the model emits a \n<think>...</think>\n block before the answer. EOS ids: 59246 (<|endoftext|>) and 59253.
Canonical OCR task prompts (user text placed after the image block):
Text Recognition:for plain text extractionFormula Recognition:for formulasTable Recognition:for tables- structured extraction:
请按下列JSON格式输出图中信息:followed by a JSON schema skeleton
Implementation plan
Per-file, with reuse decisions:
src/models/detection.rs: add"glm_ocr" => Ok(ModelType::GlmOcr)next to the"glm4v"arm. New arm.src/models/mod.rs: addModelType::GlmOcrto the enum (nearGlm4v),ALL_MODEL_TYPES, the display-name match (("GLM-OCR", "GLM VLM")), and theall_variants!list. New registrations.- Text backbone: reuse
Glm4vTextModelunchanged. The layer structure, weight-key layout (model.layers.N.*,model.embed_tokens,model.norm,lm_head), andGlm4vMRoPEall match. What must change is config plumbing insrc/models/glm4v.rs: supportrope_parameters(serde alias forrope_scalingplus optionalpartial_rotary_factor/rope_thetafields insideRopeScaling, or loader-side normalization) sorope_dims = 128andmrope_section = [16, 24, 24]come out of the checkpoint config, and thread the GLM-OCR EOS defaults[59246, 59253].attention_biasneeds no code path change (UnifiedLinearauto-loads.biaskeys only when present, and GLM-OCR text has none). src/vision/encoders/glm_ocr.rs: new file, a variant ofsrc/vision/encoders/glm4v.rs. Reuse (copy or factor out):PatchEmbed,VisionRotaryEmbedding+host_pos_ids+rotary_table, packed-attention segment loop,Downsample,PatchMerger,compute_cu_seqlens. Changes: dropVisionEmbeddingsandpost_conv_layernorm; add per-headq_norm/k_normRMSNorm(64) in the attention before rotary; take block-norm eps fromrms_norm_eps(1e-5) instead of the hardcoded 1e-6; add the conv-weight layout detection described below. Biases on qkv/proj/MLP load automatically throughUnifiedLinear.src/vision/glm_ocr.rs: new file modeled onsrc/vision/glm4v.rs(Glm4vModel). Sameget_input_embeddingsflow (embed tokens, run tower,merge::merge_llavaonimage_token_id59280, compute 3D position ids,set_mrope_state);compute_rope_indexcan be shared with glm4v since the image-only math is identical. Registerpub useinsrc/vision/mod.rs.- Connector: none needed. The downsample + merger live inside the encoder, as with glm4v (no
src/vision/connectors/entry). - Processor: reuse
src/vision/processors/qwen2_vl.rs, constructed withmin_pixels = 12544,max_pixels = 9633792(readpreprocessor_config.jsonif present, else these defaults). - Loader: add
load_glm_ocrinsrc/loading/vlm_qwen.rsbesideload_glm4v(or a smallsrc/loading/vlm_glm_ocr.rswired intosrc/loading/vlm.rsandsrc/loading/mod.rs). Reuseremap_glm4v_weights(identical prefixes), add the MTP-layer drop (below), liftrope_parameters, build the processor with GLM-OCR pixel bounds, and take token idsimage_token_id = 59280,video_token_id = 59281, start token 59256 (keyimage_start_token_id). Dispatch fromsrc/loading/mod.rs(ModelType::GlmOcr => Some(load_glm_ocr(model_path)?)). - Runtime integration: add
LoadedModel::GlmOcr(vision::GlmOcrModel)insrc/loaded_model.rs(enum + dispatch macro arm),Self::GlmOcr(model) => Some(VlmRuntimeRef::Qwen(model))insrc/loaded_model_capabilities.rs, andimpl_qwen_vl_runtime_loop_dispatch!(vision::GlmOcrModel);insrc/multimodal/qwen_vl.rs. This is what makes the model actually servable throughmlxcel-serverand the CLI; the port is not done until this wiring exists. src/model_metadata.rs: add aGlmOcrrow (kind: Vlm, directory: Vlm, adapter unsupported message), mirroring theGlm4vrow.src/distributed/tensor_parallel/inference.rs: either mapModelType::GlmOcralongsideGlm4-family entries or leave it explicitly unsupported for TP; do not let the match fall through silently.docs/supported-models.md: add a GLM-OCR entry next to the GLM-4V/PaddleOCR-VL lines describing the tower (3D patch embed, q/k-normed packed attention, Conv2d downsample, SwiGLU merger) and the GLM-4 text backbone with full-width even/odd MRoPE.- Tests: co-located unit tests plus
tests/glm_ocr_parity.rs(see Validation).
Weight loading and sanitize
Raw checkpoint key prefixes and the remap (identical to remap_glm4v_weights in src/loading/vlm_qwen.rs, reuse it):
| checkpoint key | mlxcel key |
|---|---|
model.visual.* |
vision_tower.* |
model.language_model.* |
model.* |
lm_head.weight |
lm_head.weight (unchanged) |
MTP layer drop (new sanitize step): the checkpoint contains a multi-token-prediction block at model.language_model.layers.16.* (num_nextn_predict_layers: 1; keys include eh_proj.weight (1536, 3072), embed_tokens.weight, enorm.weight, hnorm.weight, shared_head.head.weight (59392, 1536), shared_head.norm.weight, plus a full decoder layer). num_hidden_layers is 16, so inference uses layers 0..15 only; drop every key whose layer index is >= num_hidden_layers before Glm4vTextModel::from_weights (which loads strictly model.layers.0..15 and would otherwise just leak the tensors, and any generic "count the layers" logic would miscount).
Layout permutations. Checkpoints store linear weights as (out_features, in_features), applied as x @ W^T; no permutation needed. Convolutions are the exception; the checkpoint stores channels-second layouts while the in-tree matmul evaluation expects specific flatten orders:
vision_tower.patch_embed.proj.weight: stored(1024, 3, 2, 14, 14)= (out, in_channels, kT, kH, kW). The matmul weight must be(1024, 1176)flattened in the same order as the per-patch input flatten (temporal, channels, patch_h, patch_w), so permute axes[0, 2, 1, 3, 4]->(1024, 2, 3, 14, 14)= (out, kT, in, kH, kW), then reshape to(1024, 1176). The existing glm4vPatchEmbedassumes the pre-permuted channels-last layout(out, kT, kH, kW, in)=(1024, 2, 14, 14, 3)and permutes[0, 1, 4, 2, 3]; some published exports ship that layout. Detect which one arrived by shape (axis 1 == 3 and axis 2 == 2 means channels-second; axis 4 == 3 means channels-last) and permute accordingly, following the dual-layout detection precedent insrc/vision/encoders/paddleocr_vl.rs(PatchEmbed::from_weights).vision_tower.downsample.weight: stored(1536, 1024, 2, 2)= (out, in_channels, kH, kW). The downsample input is each merge window flattened from(2, 2, 1024)in (kH, kW, channels) order, so permute axes[0, 2, 3, 1]->(1536, 2, 2, 1024), then reshape to(1536, 4096). The in-tree glm4vDownsample::from_weightsreshapes without permuting (it assumes the channels-last export layout(1536, 2, 2, 1024)); loading the raw checkpoint through that code would be silently wrong, so the GLM-OCR downsample needs the same shape-based detection (axis 1 == 1024 means channels-second, axis 3 == 1024 means channels-last; the two are unambiguous because 1024 != 2).vision_tower.patch_embed.proj.bias (1024,),vision_tower.downsample.bias (1536,)and all other biases are 1-D(out_features,), no permutation.
Key inventory to load (shapes as stored): text per layer self_attn.q_proj.weight (2048, 1536), k_proj (1024, 1536), v_proj (1024, 1536), o_proj (1536, 2048), mlp.gate_up_proj.weight (9216, 1536), mlp.down_proj.weight (1536, 4608), four norm weights (1536,); model.embed_tokens.weight (59392, 1536), model.norm.weight (1536,), lm_head.weight (59392, 1536) (untied; sanitize_tied_embeddings in src/models/sanitize.rs is a no-op because tie_word_embeddings is explicitly false). Vision per block: attn.qkv.weight (3072, 1024) + bias (3072,), attn.proj.weight (1024, 1024) + bias, attn.q_norm.weight (64,), attn.k_norm.weight (64,), mlp.gate_proj.weight (4096, 1024) + bias, mlp.up_proj same, mlp.down_proj.weight (1024, 4096) + bias, norm1.weight (1024,), norm2.weight (1024,); plus post_layernorm.weight (1024,), merger.proj.weight (1536, 1536) (no bias), merger.post_projection_norm.weight + .bias (1536,), merger.gate_proj.weight (4608, 1536), merger.up_proj.weight (4608, 1536), merger.down_proj.weight (1536, 4608) (all no bias). There is no position_embedding and no post_conv_layernorm tensor; treat their presence as an error rather than loading glm4v modules by accident.
Validation and acceptance criteria
- Co-located unit tests (in the new model/encoder/loader files, plus
src/models/glm4v_tests.rs-style coverage where config code is shared):rope_parameterslifting: parsed config yieldsrope_dims = 128,mrope_section = [16, 24, 24],rope_theta = 10000; a glm4v-style config still yields the old values.- MRoPE golden values: a hand-computed cos/sin for a small position tensor at full-width even/odd pairing.
- Conv layout detection: both
(out, in, kT, kH, kW)/(out, kT, kH, kW, in)patch-embed layouts and both downsample layouts produce identical matmul weights. - MTP drop: synthetic weight map containing
model.layers.16.*keys loads a 16-layer model and ignores the extras. - Processor: smart-resize bounds honor min 12544 / max 9633792; placeholder expansion count equals
h*w/4per image.
- Synthetic parity test
tests/glm_ocr_parity.rs, modeled ontests/glm4v_parity.rs: config-detection tests that run in CI without a checkpoint (model_type: "glm_ocr"maps to the new variant), plus checkpoint-gated forward tests (text-only decode and an image forward with shape/finiteness checks and a deterministic golden comparison) that skip cleanly when the model directory is absent. - Real-checkpoint smoke test: load
zai-org/GLM-OCR(bf16, single-file safetensors) and generate through mlxcel's actual runtime (server or CLI, the same path users hit), runningText Recognition:on a document image and checking that the recognized text matches the image content; also exerciseTable Recognition:once. Include the patch-order consistency check with a spatially asymmetric image (text confined to one corner must be read correctly).
Known failure mode to design for: synthetic parity can pass while a real checkpoint breaks on weight-key layout (the MTP layer, conv layouts), config defaults (the rope_parameters nesting, mrope_section, partial_rotary_factor, EOS ids), and tokenizer/chat-template details ([gMASK]<sop>, <think> block, <|image|> expansion). Real-checkpoint load + generate is therefore the completion bar, and completion requires the model to be reachable through the working runtime (detection -> loader -> LoadedModel -> QwenVlRuntime -> server/CLI), not standalone modules that compile but are never dispatched.
Out of scope
- Video inputs (
video_grid_thw, per-frame temporal position grouping); still-image OCR only. - The MTP layer as a speculative-decoding feature (it is dropped at load, not executed).
- LoRA adapters and tensor-parallel sharding (register the metadata rows as unsupported, matching GLM-4V).
- Quantized exports: nothing extra should be needed (
UnifiedLinearauto-detects.scales/.biases), but validating a quantized variant is follow-up work, not part of this issue.
Activity
feat(models): port GLM-OCR (ViT + GLM-4 text OCR) (#646)
feat(models): port GLM-OCR (ViT + GLM-4 text OCR) (lablup#646)