Instructions to use nvidia/Riva-Translate-4B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/Riva-Translate-4B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nvidia/Riva-Translate-4B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("nvidia/Riva-Translate-4B-Instruct") model = AutoModelForCausalLM.from_pretrained("nvidia/Riva-Translate-4B-Instruct") 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 nvidia/Riva-Translate-4B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/Riva-Translate-4B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Riva-Translate-4B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nvidia/Riva-Translate-4B-Instruct
- SGLang
How to use nvidia/Riva-Translate-4B-Instruct 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 "nvidia/Riva-Translate-4B-Instruct" \ --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": "nvidia/Riva-Translate-4B-Instruct", "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 "nvidia/Riva-Translate-4B-Instruct" \ --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": "nvidia/Riva-Translate-4B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use nvidia/Riva-Translate-4B-Instruct with Docker Model Runner:
docker model run hf.co/nvidia/Riva-Translate-4B-Instruct
update the chat template
Browse files- tokenizer_config.json +1 -1
tokenizer_config.json
CHANGED
|
@@ -8005,7 +8005,7 @@
|
|
| 8005 |
}
|
| 8006 |
},
|
| 8007 |
"bos_token": "<s>",
|
| 8008 |
-
"chat_template": "{%-
|
| 8009 |
"clean_up_tokenization_spaces": false,
|
| 8010 |
"eos_token": "</s>",
|
| 8011 |
"model_max_length": 1000000000000000019884624838656,
|
|
|
|
| 8005 |
}
|
| 8006 |
},
|
| 8007 |
"bos_token": "<s>",
|
| 8008 |
+
"chat_template": "{%- set language_pairs = {\"en-zh-cn\": {\"source\": \"English\", \"target\": \"Simplified Chinese\"}, \"en-zh\": {\"source\": \"English\", \"target\": \"Simplified Chinese\"}, \"en-zh-tw\": {\"source\": \"English\", \"target\": \"Traditional Chinese\"}, \"en-ar\": {\"source\": \"English\", \"target\": \"Arabic\"}, \"en-de\": {\"source\": \"English\", \"target\": \"German\"}, \"en-es-es\": {\"source\": \"English\", \"target\": \"European Spanish\"}, \"en-es-us\": {\"source\": \"English\", \"target\": \"Latin American Spanish\"}, \"en-fr\": {\"source\": \"English\", \"target\": \"French\"}, \"en-ja\": {\"source\": \"English\", \"target\": \"Japanese\"}, \"en-ko\": {\"source\": \"English\", \"target\": \"Korean\"}, \"en-ru\": {\"source\": \"English\", \"target\": \"Russian\"}, \"en-pt-br\": {\"source\": \"English\", \"target\": \"Brazilian Portuguese\"}} -%}\n{%- set system_message = '' -%}\n{%- set source_lang = '' -%}\n{%- set target_lang = '' -%}\n{%- if messages[0]['role'] == 'system' -%}\n {%- set lang_pair = messages[0]['content'] | trim -%}\n {%- set messages = messages[1:] -%}\n {%- if lang_pair in language_pairs -%}\n {%- set source_lang = language_pairs[lang_pair]['source'] -%}\n {%- set target_lang = language_pairs[lang_pair]['target'] -%}\n {%- set system_message = 'You are an expert at translating text from ' + source_lang + ' to ' + target_lang + '.' -%}\n {%- else -%}\n {%- set system_message = 'You are a translation expert.' -%}\n {%- endif -%}\n{%- endif -%}\n{{- '<s>System\\n' + system_message + '</s>\\n' -}}\n{%- for message in messages -%}\n {%- if (message['role'] in ['user']) != (loop.index0 % 2 == 0) -%}\n {{- raise_exception('Conversation roles must alternate between user and assistant') -}}\n {%- elif message['role'] == 'user' -%}\n {%- set user_content = (target_lang and 'What is the ' + target_lang + ' translation of the sentence: ' + message['content'] | trim or message['content'] | trim) -%}\n {{- '<s>User\\n' + user_content + '</s>\\n' -}}\n {%- elif message['role'] == 'assistant' -%}\n {{- '<s>Assistant\\n' + message['content'] | trim + '</s>\\n' -}}\n {%- endif -%}\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n {{ '<s>Assistant\\n' }}\n{%- endif -%}",
|
| 8009 |
"clean_up_tokenization_spaces": false,
|
| 8010 |
"eos_token": "</s>",
|
| 8011 |
"model_max_length": 1000000000000000019884624838656,
|