Instructions to use optimum-intel-internal-testing/tiny-random-nemotron-h with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use optimum-intel-internal-testing/tiny-random-nemotron-h with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="optimum-intel-internal-testing/tiny-random-nemotron-h") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("optimum-intel-internal-testing/tiny-random-nemotron-h") model = AutoModelForCausalLM.from_pretrained("optimum-intel-internal-testing/tiny-random-nemotron-h", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use optimum-intel-internal-testing/tiny-random-nemotron-h with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "optimum-intel-internal-testing/tiny-random-nemotron-h" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "optimum-intel-internal-testing/tiny-random-nemotron-h", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/optimum-intel-internal-testing/tiny-random-nemotron-h
- SGLang
How to use optimum-intel-internal-testing/tiny-random-nemotron-h 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 "optimum-intel-internal-testing/tiny-random-nemotron-h" \ --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": "optimum-intel-internal-testing/tiny-random-nemotron-h", "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 "optimum-intel-internal-testing/tiny-random-nemotron-h" \ --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": "optimum-intel-internal-testing/tiny-random-nemotron-h", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use optimum-intel-internal-testing/tiny-random-nemotron-h with Docker Model Runner:
docker model run hf.co/optimum-intel-internal-testing/tiny-random-nemotron-h
Add tiny random NemotronH model
Browse filesMove all files from https://huggingface.co/alejandro-rodriguez/tiny-random-nemotron-h (revision 4c3c3975d15b0d4b5b24ad1d0968030a20d04be0): tiny random NemotronH model (Mamba2, MoE, attention, MLP blocks) for the OpenVINO tests of optimum-intel.
Files changed (8)
- .gitattributes+1
- README.md+77-3
- chat_template.jinjaAdded+204
- config.jsonAdded+66
- generation_config.jsonAdded+10
- model.safetensorsAdded+3
- tokenizer.jsonAdded+3
- tokenizer_config.jsonAdded+16
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353632 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -text
123---license: apache-2.0---1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677---library_name: transformerslicense: otherlicense_name: nvidia-nemotron-open-model-licenselicense_link: >-https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-nemotron-open-model-license/---Tiny random NemotronH model for the OpenVINO tests of optimum-intel. The tokenizer is the one of[nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16](https://huggingface.co/nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16).Here is the code to create this tiny model:```python"""Create a tiny random NemotronH model with every block type (Mamba2, MoE, attention, MLP).Built with transformers 5.15.1. The layer types are saved as `hybrid_override_pattern` instead of`layers_block_type`: transformers 5.13 renamed them ("mamba" -> "linear_attention", "attention" -> "full_attention")and 5.6 to 5.12 only accept the old names, while every version with NemotronH converts the pattern.Usage: python create_tiny_random_nemotron_h.py [output_dir]"""import jsonimport sysfrom pathlib import Pathimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizer, NemotronHConfig# Mamba2, MoE, attention, Mamba2, MLP, attentionHYBRID_OVERRIDE_PATTERN = "ME*M-*"output_dir = Path(sys.argv[1] if len(sys.argv) > 1 else "./tiny-random-nemotron-h")tokenizer = AutoTokenizer.from_pretrained("nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16")config = NemotronHConfig(vocab_size=len(tokenizer),hidden_size=64,hybrid_override_pattern=HYBRID_OVERRIDE_PATTERN,num_attention_heads=4,num_key_value_heads=2,# differs from hidden_size // num_attention_heads, as in NVIDIA-Nemotron-3-Nano-4Bhead_dim=32,intermediate_size=128,mamba_num_heads=8,mamba_head_dim=8,n_groups=2,ssm_state_size=16,conv_kernel=4,# several chunks for the reference SSD scan of the prompts used in testschunk_size=8,n_routed_experts=8,num_experts_per_tok=2,moe_intermediate_size=32,moe_shared_expert_intermediate_size=64,routed_scaling_factor=2.5,n_group=1,topk_group=1,tie_word_embeddings=False,)config.dtype = "float32"torch.manual_seed(42)model = AutoModelForCausalLM.from_config(config).float().eval()output_dir.mkdir(parents=True, exist_ok=True)model.save_pretrained(output_dir)tokenizer.save_pretrained(output_dir)config_file = output_dir / "config.json"saved_config = json.loads(config_file.read_text(encoding="utf-8"))saved_config.pop("layers_block_type")saved_config.pop("mtp_layers_block_type", None)saved_config["hybrid_override_pattern"] = HYBRID_OVERRIDE_PATTERNconfig_file.write_text(json.dumps(saved_config, indent=2, sort_keys=True) + "\n", encoding="utf-8")```
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204{% macro render_extra_keys(json_dict, handled_keys) %}
{%- if json_dict is mapping %}
{%- for json_key in json_dict if json_key not in handled_keys %}
{%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) %}
{{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '</' ~ json_key ~ '>' }}
{%- else %}
{{-'\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '</' ~ json_key ~ '>' }}
{%- endif %}
{%- endfor %}
{%- endif %}
{% endmacro %}
{%- set enable_thinking = enable_thinking if enable_thinking is defined else True %}
{%- set truncate_history_thinking = truncate_history_thinking if truncate_history_thinking is defined else True %}
{%- set ns = namespace(last_user_idx = -1) %}
{%- set loop_messages = messages %}
{%- for m in loop_messages %}
{%- if m["role"] == "user" %}
{%- set ns.last_user_idx = loop.index0 %}
{%- endif %}
{%- endfor %}
{%- if messages[0]["role"] == "system" %}
{%- set system_message = messages[0]["content"] %}
{%- set loop_messages = messages[1:] %}
{%- else %}
{%- set system_message = "" %}
{%- set loop_messages = messages %}
{%- endif %}
{%- if not tools is defined %}
{%- set tools = [] %}
{%- endif %}
{# Recompute last_user_idx relative to loop_messages after handling system #}
{%- set ns = namespace(last_user_idx = -1) %}
{%- for m in loop_messages %}
{%- if m["role"] == "user" %}
{%- set ns.last_user_idx = loop.index0 %}
{%- endif %}
{%- endfor %}
{%- if system_message is defined %}
{{- "<|im_start|>system\n" + system_message }}
{%- else %}
{%- if tools is iterable and tools | length > 0 %}
{{- "<|im_start|>system\n" }}
{%- endif %}
{%- endif %}
{%- if tools is iterable and tools | length > 0 %}
{%- if system_message is defined and system_message | length > 0 %}
{{- "\n\n" }}
{%- endif %}
{{- "# Tools\n\nYou have access to the following functions:\n\n" }}
{{- "<tools>" }}
{%- for tool in tools %}
{%- if tool.function is defined %}
{%- set tool = tool.function %}
{%- endif %}
{{- "\n<function>\n<name>" ~ tool.name ~ "</name>" }}
{%- if tool.description is defined %}
{{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
{%- endif %}
{{- '\n<parameters>' }}
{%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}
{%- for param_name, param_fields in tool.parameters.properties|items %}
{{- '\n<parameter>' }}
{{- '\n<name>' ~ param_name ~ '</name>' }}
{%- if param_fields.type is defined %}
{{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
{%- endif %}
{%- if param_fields.description is defined %}
{{- '\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}
{%- endif %}
{%- if param_fields.enum is defined %}
{{- '\n<enum>' ~ (param_fields.enum | tojson | safe) ~ '</enum>' }}
{%- endif %}
{%- set handled_keys = ['name', 'type', 'description', 'enum'] %}
{{- render_extra_keys(param_fields, handled_keys) }}
{{- '\n</parameter>' }}
{%- endfor %}
{%- endif %}
{% set handled_keys = ['type', 'properties', 'required'] %}
{{- render_extra_keys(tool.parameters, handled_keys) }}
{%- if tool.parameters is defined and tool.parameters.required is defined %}
{{- '\n<required>' ~ (tool.parameters.required | tojson | safe) ~ '</required>' }}
{%- endif %}
{{- '\n</parameters>' }}
{%- set handled_keys = ['type', 'name', 'description', 'parameters'] %}
{{- render_extra_keys(tool, handled_keys) }}
{{- '\n</function>' }}
{%- endfor %}
{{- "\n</tools>" }}
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
{%- endif %}
{%- if system_message is defined %}
{{- '<|im_end|>\n' }}
{%- else %}
{%- if tools is iterable and tools | length > 0 %}
{{- '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- for message in loop_messages %}
{%- if message.role == "assistant" %}
{# Add reasoning content in to content field for unified processing below. #}
{%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 %}
{%- set content = "<think>\n" ~ message.reasoning_content ~ "\n</think>\n" ~ (message.content | default('', true)) %}
{%- else %}
{%- set content = message.content | default('', true) %}
{%- if content is string -%}
{# Allow downstream logic to to take care of broken thought, only handle coherent reasoning here. #}
{%- if '<think>' not in content and '</think>' not in content -%}
{%- set content = "<think></think>" ~ content -%}
{%- endif -%}
{%- else -%}
{%- set content = content -%}
{%- endif -%}
{%- endif %}
{%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
{# Assistant message has tool calls. #}
{{- '<|im_start|>assistant\n' }}
{%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
{%- if content is string and content | trim | length > 0 %}
{%- if include_content %}
{{- (content | trim) ~ '\n' -}}
{%- else %}
{%- set c = (content | string) %}
{%- if '</think>' in c %}
{# Keep only content after the last closing think. Also generation prompt causes this. #}
{%- set c = c.split('</think>')[-1] %}
{%- elif '<think>' in c %}
{# If <think> was opened but never closed, drop the trailing think segment #}
{%- set c = c.split('<think>')[0] %}
{%- endif %}
{%- set c = "<think></think>" ~ c | trim %}
{%- if c | length > 0 %}
{{- c ~ '\n' -}}
{%- endif %}
{%- endif %}
{%- else %}
{{- "<think></think>" -}}
{%- endif %}
{%- for tool_call in message.tool_calls %}
{%- if tool_call.function is defined %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{{- '<tool_call>\n<function=' ~ tool_call.name ~ '>\n' -}}
{%- if tool_call.arguments is defined %}
{%- for args_name, args_value in tool_call.arguments|items %}
{{- '<parameter=' ~ args_name ~ '>\n' -}}
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
{{- args_value ~ '\n</parameter>\n' -}}
{%- endfor %}
{%- endif %}
{{- '</function>\n</tool_call>\n' -}}
{%- endfor %}
{{- '<|im_end|>\n' }}
{%- else %}
{# Assistant message doesn't have tool calls. #}
{%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
{{- '<|im_start|>assistant\n' ~ (content | default('', true) | string | trim) ~ '<|im_end|>\n' }}
{%- else %}
{%- set c = (content | default('', true) | string) %}
{%- if '<think>' in c and '</think>' in c %}
{%- set c = "<think></think>" ~ c.split('</think>')[-1] %}
{%- endif %}
{%- set c = c | trim %}
{%- if c | length > 0 %}
{{- '<|im_start|>assistant\n' ~ c ~ '<|im_end|>\n' }}
{%- else %}
{{- '<|im_start|>assistant\n<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- endif %}
{%- elif message.role == "user" or message.role == "system" %}
{{- '<|im_start|>' + message.role + '\n' }}
{%- set content = message.content | string %}
{{- content }}
{{- '<|im_end|>\n' }}
{%- elif message.role == "tool" %}
{%- if loop.previtem and loop.previtem.role != "tool" %}
{{- '<|im_start|>user\n' }}
{%- endif %}
{{- '<tool_response>\n' }}
{{- message.content }}
{{- '\n</tool_response>\n' }}
{%- if not loop.last and loop.nextitem.role != "tool" %}
{{- '<|im_end|>\n' }}
{%- elif loop.last %}
{{- '<|im_end|>\n' }}
{%- endif %}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>\n' }}
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
{%- if enable_thinking %}
{{- '<|im_start|>assistant\n<think>\n' }}
{%- else %}
{{- '<|im_start|>assistant\n<think></think>' }}
{%- endif %}
{%- endif %}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566{
"architectures": [
"NemotronHForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": 1,
"chunk_size": 8,
"conv_kernel": 4,
"dtype": "float32",
"eos_token_id": 2,
"expand": 2,
"head_dim": 32,
"hidden_dropout": 0.0,
"hidden_size": 64,
"hybrid_override_pattern": "ME*M-*",
"initializer_range": 0.02,
"intermediate_size": 128,
"layer_norm_epsilon": 1e-05,
"mamba_head_dim": 8,
"mamba_hidden_act": "silu",
"mamba_num_heads": 8,
"mamba_proj_bias": false,
"mamba_ssm_cache_dtype": "float32",
"max_position_embeddings": 4096,
"mlp_bias": false,
"mlp_hidden_act": "relu2",
"model_type": "nemotron_h",
"moe_intermediate_size": 32,
"moe_latent_size": null,
"moe_shared_expert_intermediate_size": 64,
"moe_shared_expert_overlap": true,
"n_group": 1,
"n_groups": 2,
"n_routed_experts": 8,
"n_shared_experts": 1,
"norm_topk_prob": true,
"num_attention_heads": 4,
"num_experts_per_tok": 2,
"num_key_value_heads": 2,
"num_logits_to_keep": 1,
"num_nextn_predict_layers": 0,
"pad_token_id": 0,
"rescale_prenorm_residual": true,
"residual_in_fp32": false,
"routed_scaling_factor": 2.5,
"sliding_window": null,
"ssm_state_size": 16,
"tie_word_embeddings": false,
"time_step_floor": 0.0001,
"time_step_limit": [
0.0,
{
"__float__": "Infinity"
}
],
"time_step_max": 0.1,
"time_step_min": 0.001,
"topk_group": 1,
"transformers_version": "5.15.1",
"use_bias": false,
"use_cache": true,
"use_conv_bias": true,
"use_mamba_kernels": true,
"vocab_size": 131072
}12345678910{
"_from_model_config": true,
"bos_token_id": 1,
"eos_token_id": 2,
"output_attentions": false,
"output_hidden_states": false,
"pad_token_id": 0,
"transformers_version": "5.15.1",
"use_cache": true
}123version https://git-lfs.github.com/spec/v1oid sha256:adae151a7d3b3f41c7c009f05b11316f1a7ed284005f273338ee4d064c70596esize 67685688123version https://git-lfs.github.com/spec/v1oid sha256:623c34567aebb18582765289fbe23d901c62704d6518d71866e0e58db892b5b7size 1707748412345678910111213141516{
"add_prefix_space": false,
"backend": "tokenizers",
"bos_token": "<s>",
"clean_up_tokenization_spaces": false,
"eos_token": "<|im_end|>",
"is_local": false,
"local_files_only": false,
"model_input_names": [
"input_ids",
"attention_mask"
],
"model_max_length": 262144,
"tokenizer_class": "TokenizersBackend",
"unk_token": "<unk>"
}.gitattributes+1
README.md+77-3
chat_template.jinjaAdded+204
config.jsonAdded+66
generation_config.jsonAdded+10
model.safetensorsAdded+3
tokenizer.jsonAdded+3
tokenizer_config.jsonAdded+16