Text Generation
Transformers
Safetensors
granitemoehybrid
language
unsloth
granite-4.0
conversational
4-bit precision
bitsandbytes
Instructions to use unsloth/granite-4.0-h-micro-unsloth-bnb-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/granite-4.0-h-micro-unsloth-bnb-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/granite-4.0-h-micro-unsloth-bnb-4bit") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("unsloth/granite-4.0-h-micro-unsloth-bnb-4bit") model = AutoModelForCausalLM.from_pretrained("unsloth/granite-4.0-h-micro-unsloth-bnb-4bit") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use unsloth/granite-4.0-h-micro-unsloth-bnb-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/granite-4.0-h-micro-unsloth-bnb-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": "unsloth/granite-4.0-h-micro-unsloth-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/unsloth/granite-4.0-h-micro-unsloth-bnb-4bit
- SGLang
How to use unsloth/granite-4.0-h-micro-unsloth-bnb-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 "unsloth/granite-4.0-h-micro-unsloth-bnb-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": "unsloth/granite-4.0-h-micro-unsloth-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "unsloth/granite-4.0-h-micro-unsloth-bnb-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": "unsloth/granite-4.0-h-micro-unsloth-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio new
How to use unsloth/granite-4.0-h-micro-unsloth-bnb-4bit with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/granite-4.0-h-micro-unsloth-bnb-4bit to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/granite-4.0-h-micro-unsloth-bnb-4bit to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/granite-4.0-h-micro-unsloth-bnb-4bit to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/granite-4.0-h-micro-unsloth-bnb-4bit", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/granite-4.0-h-micro-unsloth-bnb-4bit with Docker Model Runner:
docker model run hf.co/unsloth/granite-4.0-h-micro-unsloth-bnb-4bit
Upload folder using huggingface_hub
Browse files- chat_template.jinja +4 -0
- config.json +3 -6
- generation_config.json +1 -1
- model.safetensors +2 -2
- tokenizer_config.json +1 -1
chat_template.jinja
CHANGED
|
@@ -2,11 +2,13 @@
|
|
| 2 |
{%- set tools_system_message_suffix = '\n</tools>\n\nFor each tool call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.' %}
|
| 3 |
{%- set documents_system_message_prefix = 'You are a helpful assistant with access to the following documents. You may use one or more documents to assist with the user query.\n\nYou are given a list of documents within <documents></documents> XML tags:\n<documents>' %}
|
| 4 |
{%- set documents_system_message_suffix = '\n</documents>\n\nWrite the response to the user\'s input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data.' %}
|
|
|
|
| 5 |
{%- if available_tools is defined and available_tools %}
|
| 6 |
{%- set tools = available_tools %}
|
| 7 |
{%- endif %}
|
| 8 |
{%- set ns = namespace(tools_system_message=tools_system_message_prefix,
|
| 9 |
documents_system_message=documents_system_message_prefix,
|
|
|
|
| 10 |
system_message=''
|
| 11 |
) %}
|
| 12 |
{%- if tools %}
|
|
@@ -56,6 +58,8 @@
|
|
| 56 |
{%- endif %}
|
| 57 |
{%- if ns.system_message %}
|
| 58 |
{{- '<|start_of_role|>system<|end_of_role|>' + ns.system_message + '<|end_of_text|>\n' }}
|
|
|
|
|
|
|
| 59 |
{%- endif %}
|
| 60 |
{%- for message in messages %}
|
| 61 |
{%- set content = namespace(val='') %}
|
|
|
|
| 2 |
{%- set tools_system_message_suffix = '\n</tools>\n\nFor each tool call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.' %}
|
| 3 |
{%- set documents_system_message_prefix = 'You are a helpful assistant with access to the following documents. You may use one or more documents to assist with the user query.\n\nYou are given a list of documents within <documents></documents> XML tags:\n<documents>' %}
|
| 4 |
{%- set documents_system_message_suffix = '\n</documents>\n\nWrite the response to the user\'s input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data.' %}
|
| 5 |
+
{%- set g4_default_system_message = 'You are a helpful assistant. Please ensure responses are professional, accurate, and safe.' %}
|
| 6 |
{%- if available_tools is defined and available_tools %}
|
| 7 |
{%- set tools = available_tools %}
|
| 8 |
{%- endif %}
|
| 9 |
{%- set ns = namespace(tools_system_message=tools_system_message_prefix,
|
| 10 |
documents_system_message=documents_system_message_prefix,
|
| 11 |
+
default_system_message=g4_default_system_message,
|
| 12 |
system_message=''
|
| 13 |
) %}
|
| 14 |
{%- if tools %}
|
|
|
|
| 58 |
{%- endif %}
|
| 59 |
{%- if ns.system_message %}
|
| 60 |
{{- '<|start_of_role|>system<|end_of_role|>' + ns.system_message + '<|end_of_text|>\n' }}
|
| 61 |
+
{%- else %}
|
| 62 |
+
{{- '<|start_of_role|>system<|end_of_role|>' + ns.default_system_message + '<|end_of_text|>\n' }}
|
| 63 |
{%- endif %}
|
| 64 |
{%- for message in messages %}
|
| 65 |
{%- set content = namespace(val='') %}
|
config.json
CHANGED
|
@@ -96,13 +96,10 @@
|
|
| 96 |
"visual",
|
| 97 |
"vision_tower",
|
| 98 |
"mamba",
|
| 99 |
-
"model.layers.10.shared_mlp",
|
| 100 |
-
"model.layers.35.self_attn",
|
| 101 |
-
"model.layers.36.mamba",
|
| 102 |
"model.layers.25.shared_mlp",
|
| 103 |
"model.layers.39.shared_mlp",
|
| 104 |
-
"model.layers.
|
| 105 |
-
"model.layers.
|
| 106 |
],
|
| 107 |
"llm_int8_threshold": 6.0,
|
| 108 |
"load_in_4bit": true,
|
|
@@ -116,7 +113,7 @@
|
|
| 116 |
"router_aux_loss_coef": 0.01,
|
| 117 |
"shared_intermediate_size": 8192,
|
| 118 |
"tie_word_embeddings": true,
|
| 119 |
-
"transformers_version": "4.
|
| 120 |
"unsloth_fixed": true,
|
| 121 |
"use_cache": true,
|
| 122 |
"vocab_size": 100352
|
|
|
|
| 96 |
"visual",
|
| 97 |
"vision_tower",
|
| 98 |
"mamba",
|
|
|
|
|
|
|
|
|
|
| 99 |
"model.layers.25.shared_mlp",
|
| 100 |
"model.layers.39.shared_mlp",
|
| 101 |
+
"model.layers.14.shared_mlp",
|
| 102 |
+
"model.layers.34.shared_mlp"
|
| 103 |
],
|
| 104 |
"llm_int8_threshold": 6.0,
|
| 105 |
"load_in_4bit": true,
|
|
|
|
| 113 |
"router_aux_loss_coef": 0.01,
|
| 114 |
"shared_intermediate_size": 8192,
|
| 115 |
"tie_word_embeddings": true,
|
| 116 |
+
"transformers_version": "4.57.0",
|
| 117 |
"unsloth_fixed": true,
|
| 118 |
"use_cache": true,
|
| 119 |
"vocab_size": 100352
|
generation_config.json
CHANGED
|
@@ -4,5 +4,5 @@
|
|
| 4 |
"eos_token_id": 100257,
|
| 5 |
"max_length": 131072,
|
| 6 |
"pad_token_id": 100256,
|
| 7 |
-
"transformers_version": "4.
|
| 8 |
}
|
|
|
|
| 4 |
"eos_token_id": 100257,
|
| 5 |
"max_length": 131072,
|
| 6 |
"pad_token_id": 100256,
|
| 7 |
+
"transformers_version": "4.57.0"
|
| 8 |
}
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf1911069e33cbbde69d61ede04e7cc66c2359caa33f05ad226f920564e7435b
|
| 3 |
+
size 3631606927
|
tokenizer_config.json
CHANGED
|
@@ -780,5 +780,5 @@
|
|
| 780 |
"padding_side": "left",
|
| 781 |
"tokenizer_class": "GPT2Tokenizer",
|
| 782 |
"unk_token": "<|unk|>",
|
| 783 |
-
"chat_template": "{%- set tools_system_message_prefix = 'You are a helpful assistant with access to the following tools. You may call one or more tools to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>' %}\n{%- set tools_system_message_suffix = '\\n</tools>\\n\\nFor each tool call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call>. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.' %}\n{%- set documents_system_message_prefix = 'You are a helpful assistant with access to the following documents. You may use one or more documents to assist with the user query.\\n\\nYou are given a list of documents within <documents></documents> XML tags:\\n<documents>' %}\n{%- set documents_system_message_suffix = '\\n</documents>\\n\\nWrite the response to the user\\'s input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data.' %}\n{%- if available_tools is defined and available_tools %}\n {%- set tools = available_tools %}\n{%- endif %}\n{%- set ns = namespace(tools_system_message=tools_system_message_prefix,\n documents_system_message=documents_system_message_prefix,\n system_message=''\n ) %}\n{%- if tools %}\n {%- for tool in tools %}\n {%- set ns.tools_system_message = ns.tools_system_message + '\\n' + (tool | tojson) %}\n {%- endfor %}\n {%- set ns.tools_system_message = ns.tools_system_message + tools_system_message_suffix %}\n{%- else %}\n {%- set ns.tools_system_message = '' %}\n{%- endif %}\n{%- if documents %}\n {%- for document in documents %}\n {%- set ns.documents_system_message = ns.documents_system_message + '\\n' + (document | tojson) %}\n {%- endfor %}\n {%- set ns.documents_system_message = ns.documents_system_message + documents_system_message_suffix %}\n{%- else %}\n {%- set ns.documents_system_message = '' %}\n{%- endif %}\n{%- if messages[0].role == 'system' %}\n {%- if messages[0].content is string %}\n {%- set ns.system_message = messages[0].content %}\n {%- elif messages[0].content is iterable %}\n {%- for entry in messages[0].content %}\n {%- if entry.type== 'text' %}\n {%- if ns.system_message != '' %}\n {%- set ns.system_message = ns.system_message + '\\n' %}\n {%- endif %}\n {%- set ns.system_message = ns.system_message + entry.text %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- if tools and documents %}\n {%- set ns.system_message = ns.system_message + '\\n\\n' + ns.tools_system_message + '\\n\\n' + ns.documents_system_message %}\n {%- elif tools %}\n {%- set ns.system_message = ns.system_message + '\\n\\n' + ns.tools_system_message %}\n {%- elif documents %}\n {%- set ns.system_message = ns.system_message + '\\n\\n' + ns.documents_system_message %}\n {%- endif %}\n{%- else %}\n {%- if tools and documents %}\n {%- set ns.system_message = ns.tools_system_message + '\\n\\n' + ns.documents_system_message %}\n {%- elif tools %}\n {%- set ns.system_message = ns.tools_system_message %}\n {%- elif documents %}\n {%- set ns.system_message = ns.documents_system_message %}\n {%- endif %}\n{%- endif %}\n{%- if ns.system_message %}\n {{- '<|start_of_role|>system<|end_of_role|>' + ns.system_message + '<|end_of_text|>\\n' }}\n{%- endif %}\n{%- for message in messages %}\n {%- set content = namespace(val='') %}\n {%- if message.content is string %}\n {%- set content.val = message.content %}\n {%- else %}\n {%- if message.content is iterable %}\n {%- for entry in message.content %}\n {%- if entry.type== 'text' %}\n {%- if content.val != '' %}\n {%- set content.val = content.val + '\\n' %}\n {%- endif %}\n {%- set content.val = content.val + entry.text %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- endif %}\n {%- if (message.role == 'user') or (message.role == 'system' and not loop.first) %}\n {{- '<|start_of_role|>' + message.role + '<|end_of_role|>' + content.val + '<|end_of_text|>\\n' }}\n {%- elif message.role == 'assistant' %}\n {{- '<|start_of_role|>' + message.role + '<|end_of_role|>' + content.val }}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content.val) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|end_of_text|>\\n' }}\n {%- elif message.role == 'tool' %}\n {%- if loop.first or (messages[loop.index0 - 1].role != 'tool') %}\n {{- '<|start_of_role|>user<|end_of_role|>' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content.val }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != 'tool') %}\n {{- '<|end_of_text|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|start_of_role|>assistant<|end_of_role|>' }}\n{%- endif %}"
|
| 784 |
}
|
|
|
|
| 780 |
"padding_side": "left",
|
| 781 |
"tokenizer_class": "GPT2Tokenizer",
|
| 782 |
"unk_token": "<|unk|>",
|
| 783 |
+
"chat_template": "{%- set tools_system_message_prefix = 'You are a helpful assistant with access to the following tools. You may call one or more tools to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>' %}\n{%- set tools_system_message_suffix = '\\n</tools>\\n\\nFor each tool call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call>. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.' %}\n{%- set documents_system_message_prefix = 'You are a helpful assistant with access to the following documents. You may use one or more documents to assist with the user query.\\n\\nYou are given a list of documents within <documents></documents> XML tags:\\n<documents>' %}\n{%- set documents_system_message_suffix = '\\n</documents>\\n\\nWrite the response to the user\\'s input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data.' %}\n{%- set g4_default_system_message = 'You are a helpful assistant. Please ensure responses are professional, accurate, and safe.' %}\n{%- if available_tools is defined and available_tools %}\n {%- set tools = available_tools %}\n{%- endif %}\n{%- set ns = namespace(tools_system_message=tools_system_message_prefix,\n documents_system_message=documents_system_message_prefix,\n default_system_message=g4_default_system_message,\n system_message=''\n ) %}\n{%- if tools %}\n {%- for tool in tools %}\n {%- set ns.tools_system_message = ns.tools_system_message + '\\n' + (tool | tojson) %}\n {%- endfor %}\n {%- set ns.tools_system_message = ns.tools_system_message + tools_system_message_suffix %}\n{%- else %}\n {%- set ns.tools_system_message = '' %}\n{%- endif %}\n{%- if documents %}\n {%- for document in documents %}\n {%- set ns.documents_system_message = ns.documents_system_message + '\\n' + (document | tojson) %}\n {%- endfor %}\n {%- set ns.documents_system_message = ns.documents_system_message + documents_system_message_suffix %}\n{%- else %}\n {%- set ns.documents_system_message = '' %}\n{%- endif %}\n{%- if messages[0].role == 'system' %}\n {%- if messages[0].content is string %}\n {%- set ns.system_message = messages[0].content %}\n {%- elif messages[0].content is iterable %}\n {%- for entry in messages[0].content %}\n {%- if entry.type== 'text' %}\n {%- if ns.system_message != '' %}\n {%- set ns.system_message = ns.system_message + '\\n' %}\n {%- endif %}\n {%- set ns.system_message = ns.system_message + entry.text %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- if tools and documents %}\n {%- set ns.system_message = ns.system_message + '\\n\\n' + ns.tools_system_message + '\\n\\n' + ns.documents_system_message %}\n {%- elif tools %}\n {%- set ns.system_message = ns.system_message + '\\n\\n' + ns.tools_system_message %}\n {%- elif documents %}\n {%- set ns.system_message = ns.system_message + '\\n\\n' + ns.documents_system_message %}\n {%- endif %}\n{%- else %}\n {%- if tools and documents %}\n {%- set ns.system_message = ns.tools_system_message + '\\n\\n' + ns.documents_system_message %}\n {%- elif tools %}\n {%- set ns.system_message = ns.tools_system_message %}\n {%- elif documents %}\n {%- set ns.system_message = ns.documents_system_message %}\n {%- endif %}\n{%- endif %}\n{%- if ns.system_message %}\n {{- '<|start_of_role|>system<|end_of_role|>' + ns.system_message + '<|end_of_text|>\\n' }}\n{%- else %}\n {{- '<|start_of_role|>system<|end_of_role|>' + ns.default_system_message + '<|end_of_text|>\\n' }}\n{%- endif %}\n{%- for message in messages %}\n {%- set content = namespace(val='') %}\n {%- if message.content is string %}\n {%- set content.val = message.content %}\n {%- else %}\n {%- if message.content is iterable %}\n {%- for entry in message.content %}\n {%- if entry.type== 'text' %}\n {%- if content.val != '' %}\n {%- set content.val = content.val + '\\n' %}\n {%- endif %}\n {%- set content.val = content.val + entry.text %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- endif %}\n {%- if (message.role == 'user') or (message.role == 'system' and not loop.first) %}\n {{- '<|start_of_role|>' + message.role + '<|end_of_role|>' + content.val + '<|end_of_text|>\\n' }}\n {%- elif message.role == 'assistant' %}\n {{- '<|start_of_role|>' + message.role + '<|end_of_role|>' + content.val }}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content.val) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|end_of_text|>\\n' }}\n {%- elif message.role == 'tool' %}\n {%- if loop.first or (messages[loop.index0 - 1].role != 'tool') %}\n {{- '<|start_of_role|>user<|end_of_role|>' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content.val }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != 'tool') %}\n {{- '<|end_of_text|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|start_of_role|>assistant<|end_of_role|>' }}\n{%- endif %}"
|
| 784 |
}
|