Instructions to use google/gemma-4-31B-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-4-31B-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="google/gemma-4-31B-it") 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, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("google/gemma-4-31B-it") model = AutoModelForMultimodalLM.from_pretrained("google/gemma-4-31B-it", device_map="auto") 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]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- AMD Developer Cloud
- Local Apps Settings
- vLLM
How to use google/gemma-4-31B-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/gemma-4-31B-it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/gemma-4-31B-it", "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/google/gemma-4-31B-it
- SGLang
How to use google/gemma-4-31B-it 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 "google/gemma-4-31B-it" \ --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": "google/gemma-4-31B-it", "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 "google/gemma-4-31B-it" \ --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": "google/gemma-4-31B-it", "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" } } ] } ] }' - Docker Model Runner
How to use google/gemma-4-31B-it with Docker Model Runner:
docker model run hf.co/google/gemma-4-31B-it
How did you achieve such remarkable metrics?
Hello!
Gemma is my favorite model family! I'm so grateful that they're being published. One thing's a shame: there's no 100b version of the parameters. Unfortunately, a 31b model can't be an encyclopedia. Oh well!
Could you please tell me how the developers managed to achieve such excellent metrics? How did they manage to cram so much power into 32 gigabytes?
That's my question. But this question is just a pretext for starting a thread.
My real question is this:
I'm planning to train a 16-megabyte language model myself.
So, where can I find a dataset large enough for the model to learn the grammar without overfitting? And one that produces meaningful output?
It would be ideal if the dataset came with testing tasks.
Which dataset would be suitable for me? The model has a non-standard architecture. Not a transformer, and not even a neural network. A Tsetlin machine.
Curiosity got the better of me..
16-megabyte language model? What actual parameter count/design?
Because to try to semi-answer your question there are many datasets that would be plenty for a 16-megabyte model.
I am only very, very passingly familiar with Tsetlin though, so apologies if the framing doesn't make sense in context.
Look, in Tsetlin's machine, one parameter is essentially one bit. In compressed form.
But I don't know how much the uncompressed version will weigh. The uncompressed version can be trained. The compressed version is essentially one big logical formula.
I'd be very interested if you could give me links to one or more datasets. I just don't know how to search.
Finite state machine basically?
Anyway, in an attempt to give a helpful answer, there are things like:
https://huggingface.co/datasets/Crownelius/Opus-4.6-Reasoning-2100x-formatted (and many such similar ones)
https://huggingface.co/datasets/amd/InstructGpt-educational
Good ol fineweb:
https://huggingface.co/datasets/HuggingFaceFW/fineweb
This isn't a finite state machine.
I recommend you read the original article to get a rough idea.
Oh, thank you, I'll read that over sometime and try to learn more about the topic.
Look at https://github.com/arman-bd/guppylm, maybe it fulfills your need of a MB-sized Modell training.
Look at https://github.com/arman-bd/guppylm, maybe it fulfills your need of a MB-sized Modell training.
And philosophy! :)