Instructions to use immanuelpeter/GLM-5.3-Flash-Vision with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use immanuelpeter/GLM-5.3-Flash-Vision with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="immanuelpeter/GLM-5.3-Flash-Vision")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("immanuelpeter/GLM-5.3-Flash-Vision") model = AutoModel.from_pretrained("immanuelpeter/GLM-5.3-Flash-Vision", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add immanuelpeter/GLM-5.3-Flash-Vision vision tower
Browse files- LICENSE +21 -0
- README.md +55 -0
- config.json +29 -0
- examples/inference.py +35 -0
- model.safetensors +3 -0
- preprocessor_config.json +21 -0
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 Z.AI Co., Ltd
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
pipeline_tag: image-feature-extraction
|
| 4 |
+
library_name: transformers
|
| 5 |
+
tags:
|
| 6 |
+
- vision
|
| 7 |
+
base_model:
|
| 8 |
+
- zai-org/GLM-5.3-Flash
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# GLM-5.3-Flash Vision
|
| 12 |
+
|
| 13 |
+
This repository packages the native vision encoder and learned merger from
|
| 14 |
+
[GLM-5.3-Flash](https://huggingface.co/zai-org/GLM-5.3-Flash).
|
| 15 |
+
|
| 16 |
+
## Contents
|
| 17 |
+
|
| 18 |
+
| File | Tensors | What it holds |
|
| 19 |
+
|---|---|---|
|
| 20 |
+
| `model.safetensors` | 347 | Tower and learned merger, extracted from source shard 62 |
|
| 21 |
+
| `config.json` | | Vision-only `Glm5NextVisionConfig` |
|
| 22 |
+
| `preprocessor_config.json` | | GLM image preprocessing configuration |
|
| 23 |
+
|
| 24 |
+
## Architecture
|
| 25 |
+
|
| 26 |
+
| Component | Details |
|
| 27 |
+
|---|---|
|
| 28 |
+
| Tower | 24 blocks, 1024 hidden, 16 heads, 4096 intermediate, patch size 14, image size 448, axial 2D-RoPE, silu |
|
| 29 |
+
| Patch embed | Conv3d, temporal patch size 2 |
|
| 30 |
+
| Token compression | 2x2 spatial grouping of 1024-wide patches to 4096 |
|
| 31 |
+
| Learned merger | `Linear(4096, 4096)` no bias, `LayerNorm(4096)`, GELU, SwiGLU with `Linear(4096, 10240)` gate and up, `Linear(10240, 4096)` down, silu, clamp 10 |
|
| 32 |
+
|
| 33 |
+
## Usage
|
| 34 |
+
|
| 35 |
+
See [`examples/inference.py`](examples/inference.py) for image feature extraction.
|
| 36 |
+
|
| 37 |
+
## Validation
|
| 38 |
+
|
| 39 |
+
The [parity script](https://github.com/immanuel-peter/vision-tower-bench/blob/main/tests/test_parity.py)
|
| 40 |
+
compares all 347 tensors with the pinned parent checkpoint using `torch.equal`.
|
| 41 |
+
|
| 42 |
+
## Reproduction
|
| 43 |
+
|
| 44 |
+
The [export script](https://github.com/immanuel-peter/vision-tower-bench/blob/main/scripts/export_glm5_vision.py)
|
| 45 |
+
reads `model.visual.*` from shard 62 of `zai-org/GLM-5.3-Flash`, removes the prefix, and
|
| 46 |
+
writes the original BF16 tensors. It copies the image section of the parent processor
|
| 47 |
+
configuration.
|
| 48 |
+
|
| 49 |
+
## Credits
|
| 50 |
+
|
| 51 |
+
Z.ai released the GLM-5.3-Flash weights and the native Transformers implementation.
|
| 52 |
+
|
| 53 |
+
## License
|
| 54 |
+
|
| 55 |
+
[MIT License](LICENSE), the same license as the source model.
|
config.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Glm5NextVisionModel"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": true,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"depth": 24,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"hidden_act": "silu",
|
| 10 |
+
"hidden_size": 1024,
|
| 11 |
+
"image_size": 448,
|
| 12 |
+
"in_channels": 3,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 4096,
|
| 15 |
+
"model_type": "glm5_next_vision",
|
| 16 |
+
"num_heads": 16,
|
| 17 |
+
"out_hidden_size": 4096,
|
| 18 |
+
"patch_size": 14,
|
| 19 |
+
"projection_intermediate_size": 10240,
|
| 20 |
+
"rms_norm_eps": 1e-05,
|
| 21 |
+
"rope_parameters": {
|
| 22 |
+
"rope_theta": 10000.0,
|
| 23 |
+
"rope_type": "axial"
|
| 24 |
+
},
|
| 25 |
+
"spatial_merge_size": 2,
|
| 26 |
+
"swiglu_limit": 10.0,
|
| 27 |
+
"temporal_patch_size": 2,
|
| 28 |
+
"transformers_version": "5.17.0"
|
| 29 |
+
}
|
examples/inference.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import torch
|
| 6 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
MODEL_ID = "immanuelpeter/GLM-5.3-Flash-Vision"
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def main() -> None:
|
| 13 |
+
parser = argparse.ArgumentParser(description="Extract GLM-5.3-Flash visual features.")
|
| 14 |
+
parser.add_argument("image", type=Path)
|
| 15 |
+
parser.add_argument("--model", default=MODEL_ID)
|
| 16 |
+
args = parser.parse_args()
|
| 17 |
+
|
| 18 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 19 |
+
dtype = torch.bfloat16 if device.type == "cuda" else torch.float32
|
| 20 |
+
tower = AutoModel.from_pretrained(args.model, dtype=dtype).to(device).eval()
|
| 21 |
+
processor = AutoImageProcessor.from_pretrained(args.model)
|
| 22 |
+
inputs = processor(images=Image.open(args.image).convert("RGB"), return_tensors="pt")
|
| 23 |
+
|
| 24 |
+
with torch.inference_mode():
|
| 25 |
+
output = tower(
|
| 26 |
+
hidden_states=inputs["pixel_values"].to(device=device, dtype=dtype),
|
| 27 |
+
grid_thw=inputs["image_grid_thw"].to(device),
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
print("tower", output.last_hidden_state.shape)
|
| 31 |
+
print("projected", output.pooler_output.shape)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
main()
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e9ad22c4499407efe589f1ddf15ae39f5b62937f7fac720d4a5942a6061529cc
|
| 3 |
+
size 1127288432
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_rescale": true,
|
| 3 |
+
"patch_expand_factor": 1,
|
| 4 |
+
"merge_size": 2,
|
| 5 |
+
"image_mean": [
|
| 6 |
+
0.48145466,
|
| 7 |
+
0.4578275,
|
| 8 |
+
0.40821073
|
| 9 |
+
],
|
| 10 |
+
"image_std": [
|
| 11 |
+
0.26862954,
|
| 12 |
+
0.26130258,
|
| 13 |
+
0.27577711
|
| 14 |
+
],
|
| 15 |
+
"temporal_patch_size": 2,
|
| 16 |
+
"patch_size": 14,
|
| 17 |
+
"min_image_tokens": 16,
|
| 18 |
+
"max_image_tokens": 8000,
|
| 19 |
+
"image_processor_type": "Glm5NextImageProcessor",
|
| 20 |
+
"processor_class": "AutoImageProcessor"
|
| 21 |
+
}
|