Instructions to use tiny-random/gemma-3n-dim4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/gemma-3n-dim4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/gemma-3n-dim4") 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("tiny-random/gemma-3n-dim4") model = AutoModelForImageTextToText.from_pretrained("tiny-random/gemma-3n-dim4") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use tiny-random/gemma-3n-dim4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/gemma-3n-dim4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/gemma-3n-dim4", "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/tiny-random/gemma-3n-dim4
- SGLang
How to use tiny-random/gemma-3n-dim4 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 "tiny-random/gemma-3n-dim4" \ --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": "tiny-random/gemma-3n-dim4", "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 "tiny-random/gemma-3n-dim4" \ --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": "tiny-random/gemma-3n-dim4", "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 tiny-random/gemma-3n-dim4 with Docker Model Runner:
docker model run hf.co/tiny-random/gemma-3n-dim4
Upload folder using huggingface_hub
Browse files- README.md +1 -41
- config.json +1 -5
- preprocessor_config.json +1 -1
README.md
CHANGED
|
@@ -15,47 +15,7 @@ This tiny model is for debugging. It is randomly initialized with the config ada
|
|
| 15 |
### Example usage:
|
| 16 |
|
| 17 |
```python
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
from transformers import pipeline
|
| 21 |
-
|
| 22 |
-
model_id = "tiny-random/gemma-3n-dim4"
|
| 23 |
-
pipe = pipeline(
|
| 24 |
-
task="image-text-to-text",
|
| 25 |
-
model=model_id,
|
| 26 |
-
device=0,
|
| 27 |
-
torch_dtype=torch.bfloat16
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
# temporary patch for audio tower
|
| 31 |
-
from accelerate.hooks import ModelHook, add_hook_to_module
|
| 32 |
-
|
| 33 |
-
class EnsureDtype(ModelHook):
|
| 34 |
-
def pre_forward(self, module, *args, **kwargs):
|
| 35 |
-
args = list(args)
|
| 36 |
-
args[0] = args[0].to(module.dtype)
|
| 37 |
-
return super().pre_forward(module, *args, **kwargs)
|
| 38 |
-
add_hook_to_module(pipe.model.audio_tower, EnsureDtype())
|
| 39 |
-
|
| 40 |
-
messages = [
|
| 41 |
-
{
|
| 42 |
-
"role": "system",
|
| 43 |
-
"content": [
|
| 44 |
-
{"type": "text", "text": "You are a helpful assistant."}
|
| 45 |
-
]
|
| 46 |
-
},
|
| 47 |
-
{
|
| 48 |
-
"role": "user",
|
| 49 |
-
"content": [
|
| 50 |
-
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"},
|
| 51 |
-
# audio is buggy for now: bf16 x fp32
|
| 52 |
-
{"type": "audio", "url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Audio/glass-breaking-151256.mp3"},
|
| 53 |
-
{"type": "text", "text": "Which image is cuter?"},
|
| 54 |
-
]
|
| 55 |
-
},
|
| 56 |
-
]
|
| 57 |
-
result = pipe(messages, min_new_tokens=512, max_new_tokens=512, do_sample=True)
|
| 58 |
-
print(result)
|
| 59 |
```
|
| 60 |
|
| 61 |
### Codes to create this repo:
|
|
|
|
| 15 |
### Example usage:
|
| 16 |
|
| 17 |
```python
|
| 18 |
+
{code_to_run.strip()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
```
|
| 20 |
|
| 21 |
### Codes to create this repo:
|
config.json
CHANGED
|
@@ -10,7 +10,6 @@
|
|
| 10 |
"conf_conv_kernel_size": 5,
|
| 11 |
"conf_num_attention_heads": 2,
|
| 12 |
"conf_num_hidden_layers": 2,
|
| 13 |
-
"conf_positional_bias_size": 256,
|
| 14 |
"conf_reduction_factor": 4,
|
| 15 |
"conf_residual_weight": 0.5,
|
| 16 |
"gradient_clipping": 10000000000.0,
|
|
@@ -22,7 +21,6 @@
|
|
| 22 |
128,
|
| 23 |
32
|
| 24 |
],
|
| 25 |
-
"sscp_conv_eps": 0.001,
|
| 26 |
"sscp_conv_group_norm_eps": 0.001,
|
| 27 |
"sscp_conv_kernel_size": [
|
| 28 |
[
|
|
@@ -71,7 +69,6 @@
|
|
| 71 |
"altup_active_idx": 0,
|
| 72 |
"altup_coef_clip": 120.0,
|
| 73 |
"altup_correct_scale": true,
|
| 74 |
-
"altup_lr_multiplier": 1.0,
|
| 75 |
"altup_num_inputs": 4,
|
| 76 |
"attention_bias": false,
|
| 77 |
"attention_dropout": 0.0,
|
|
@@ -100,7 +97,6 @@
|
|
| 100 |
"num_hidden_layers": 4,
|
| 101 |
"num_key_value_heads": 1,
|
| 102 |
"num_kv_shared_layers": 2,
|
| 103 |
-
"query_pre_attn_scalar": 256,
|
| 104 |
"rms_norm_eps": 1e-06,
|
| 105 |
"rope_local_base_freq": 10000.0,
|
| 106 |
"rope_scaling": null,
|
|
@@ -115,7 +111,7 @@
|
|
| 115 |
"transformers_version": "4.54.0.dev0",
|
| 116 |
"vision_config": {
|
| 117 |
"architecture": "mobilenetv5_300m_enc",
|
| 118 |
-
"do_pooling":
|
| 119 |
"hidden_size": 2048,
|
| 120 |
"initializer_range": 0.02,
|
| 121 |
"label_names": [
|
|
|
|
| 10 |
"conf_conv_kernel_size": 5,
|
| 11 |
"conf_num_attention_heads": 2,
|
| 12 |
"conf_num_hidden_layers": 2,
|
|
|
|
| 13 |
"conf_reduction_factor": 4,
|
| 14 |
"conf_residual_weight": 0.5,
|
| 15 |
"gradient_clipping": 10000000000.0,
|
|
|
|
| 21 |
128,
|
| 22 |
32
|
| 23 |
],
|
|
|
|
| 24 |
"sscp_conv_group_norm_eps": 0.001,
|
| 25 |
"sscp_conv_kernel_size": [
|
| 26 |
[
|
|
|
|
| 69 |
"altup_active_idx": 0,
|
| 70 |
"altup_coef_clip": 120.0,
|
| 71 |
"altup_correct_scale": true,
|
|
|
|
| 72 |
"altup_num_inputs": 4,
|
| 73 |
"attention_bias": false,
|
| 74 |
"attention_dropout": 0.0,
|
|
|
|
| 97 |
"num_hidden_layers": 4,
|
| 98 |
"num_key_value_heads": 1,
|
| 99 |
"num_kv_shared_layers": 2,
|
|
|
|
| 100 |
"rms_norm_eps": 1e-06,
|
| 101 |
"rope_local_base_freq": 10000.0,
|
| 102 |
"rope_scaling": null,
|
|
|
|
| 111 |
"transformers_version": "4.54.0.dev0",
|
| 112 |
"vision_config": {
|
| 113 |
"architecture": "mobilenetv5_300m_enc",
|
| 114 |
+
"do_pooling": false,
|
| 115 |
"hidden_size": 2048,
|
| 116 |
"initializer_range": 0.02,
|
| 117 |
"label_names": [
|
preprocessor_config.json
CHANGED
|
@@ -41,7 +41,7 @@
|
|
| 41 |
"processor_class": "Gemma3nProcessor",
|
| 42 |
"resample": 2,
|
| 43 |
"rescale_factor": 0.00392156862745098,
|
| 44 |
-
"return_attention_mask":
|
| 45 |
"return_tensors": null,
|
| 46 |
"sampling_rate": 16000,
|
| 47 |
"size": {
|
|
|
|
| 41 |
"processor_class": "Gemma3nProcessor",
|
| 42 |
"resample": 2,
|
| 43 |
"rescale_factor": 0.00392156862745098,
|
| 44 |
+
"return_attention_mask": true,
|
| 45 |
"return_tensors": null,
|
| 46 |
"sampling_rate": 16000,
|
| 47 |
"size": {
|