Instructions to use mlx-community/GLM-4.6V-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mlx-community/GLM-4.6V-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="mlx-community/GLM-4.6V-4bit") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("mlx-community/GLM-4.6V-4bit") model = AutoModelForImageTextToText.from_pretrained("mlx-community/GLM-4.6V-4bit") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - MLX
How to use mlx-community/GLM-4.6V-4bit with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("mlx-community/GLM-4.6V-4bit") config = load_config("mlx-community/GLM-4.6V-4bit") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- LM Studio
- vLLM
How to use mlx-community/GLM-4.6V-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mlx-community/GLM-4.6V-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/GLM-4.6V-4bit", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/mlx-community/GLM-4.6V-4bit
- SGLang
How to use mlx-community/GLM-4.6V-4bit with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "mlx-community/GLM-4.6V-4bit" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/GLM-4.6V-4bit", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "mlx-community/GLM-4.6V-4bit" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/GLM-4.6V-4bit", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Pi new
How to use mlx-community/GLM-4.6V-4bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/GLM-4.6V-4bit"
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "mlx-community/GLM-4.6V-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use mlx-community/GLM-4.6V-4bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/GLM-4.6V-4bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default mlx-community/GLM-4.6V-4bit
Run Hermes
hermes
- Docker Model Runner
How to use mlx-community/GLM-4.6V-4bit with Docker Model Runner:
docker model run hf.co/mlx-community/GLM-4.6V-4bit
TypeError: TextConfig.__init__() missing 1 required positional argument: 'rope_theta'
Get this error when using mlx-vlm 0.3.9 on the command-line (as per example in the Model card)
same! i was being an idiot trying to solve this over on the official GLM 4.6V thread. transformers update there obviously didnt help lol. would love to figure out how to try this!
When downloading the latest mlx-vlm from github, it gives
The tokenizer you are loading from 'mlx-community_GLM-4.6V-Flash-4bit' with an incorrect regex pattern: https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503/discussions/84#69121093e8b480e709447d5e. This will lead to incorrect tokenization. You should set the fix_mistral_regex=True flag when loading this tokenizer to fix this issue.
ValueError: Failed to process inputs with error: PreTrainedTokenizerFast._batch_encode_plus() got an unexpected keyword argument 'images'
Thank you to @Timmy-web
This solved the problem: pip install git+https://github.com/huggingface/transformers.git
i tried the same pip install git+https://github.com/huggingface/transformers.git but it doesnt solve it for me, ive got the same error still. =( =(
i thought it might be because i had downloaded through lm studio. but same exact problem when loading it directly with instructions on the model card. could this be because of my python verison? running out of possiblities here.
im on python 3.11.11
I first ran pip install -U mlx-vlm, and it provided me version 0.3.9. I see that LM Studio still uses 0.3.7. Then I ran git clone https://github.com/Blaizzy/mlx-vlm.git and used that copy of mlx-vlm. This picks up the latest code changes after version 0.3.9. That's when I got the tokenization error. Then Timmy-web gave the hint to also install the transformers code, which worked.
I'm also on python 3.11
ah ha! awesome thanks! that solved it. so basically just need the latest latest version of mlx-vlm. the pip version is basically not update yet. the cost of the bleeding edge life haha.
for anyone else reading it. I uninstalled mlx-vlm with pip uninstall mlx-vlm, grabbed the latest with git clone https://github.com/Blaizzy/mlx-vlm.git, then within that mlx-vlm folder, did pip install . which gave me the latest
all that is to say most of this should like resolve itself once all the packages are updated with pip~