Text Generation
Transformers
Safetensors
GGUF
Vietnamese
mistral
LLMs
NLP
Vietnamese
conversational
text-generation-inference
Instructions to use ngxson/Vistral-7B-ChatML with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ngxson/Vistral-7B-ChatML with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ngxson/Vistral-7B-ChatML") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ngxson/Vistral-7B-ChatML") model = AutoModelForCausalLM.from_pretrained("ngxson/Vistral-7B-ChatML") 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]:])) - llama-cpp-python
How to use ngxson/Vistral-7B-ChatML with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="ngxson/Vistral-7B-ChatML", filename="vistral-7b-chatml-Q4_K_M.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use ngxson/Vistral-7B-ChatML with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf ngxson/Vistral-7B-ChatML:Q4_K_M # Run inference directly in the terminal: llama-cli -hf ngxson/Vistral-7B-ChatML:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf ngxson/Vistral-7B-ChatML:Q4_K_M # Run inference directly in the terminal: llama-cli -hf ngxson/Vistral-7B-ChatML:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf ngxson/Vistral-7B-ChatML:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf ngxson/Vistral-7B-ChatML:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf ngxson/Vistral-7B-ChatML:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf ngxson/Vistral-7B-ChatML:Q4_K_M
Use Docker
docker model run hf.co/ngxson/Vistral-7B-ChatML:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use ngxson/Vistral-7B-ChatML with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ngxson/Vistral-7B-ChatML" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ngxson/Vistral-7B-ChatML", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ngxson/Vistral-7B-ChatML:Q4_K_M
- SGLang
How to use ngxson/Vistral-7B-ChatML 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 "ngxson/Vistral-7B-ChatML" \ --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": "ngxson/Vistral-7B-ChatML", "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 "ngxson/Vistral-7B-ChatML" \ --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": "ngxson/Vistral-7B-ChatML", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use ngxson/Vistral-7B-ChatML with Ollama:
ollama run hf.co/ngxson/Vistral-7B-ChatML:Q4_K_M
- Unsloth Studio
How to use ngxson/Vistral-7B-ChatML 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 ngxson/Vistral-7B-ChatML 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 ngxson/Vistral-7B-ChatML to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for ngxson/Vistral-7B-ChatML to start chatting
- Docker Model Runner
How to use ngxson/Vistral-7B-ChatML with Docker Model Runner:
docker model run hf.co/ngxson/Vistral-7B-ChatML:Q4_K_M
- Lemonade
How to use ngxson/Vistral-7B-ChatML with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull ngxson/Vistral-7B-ChatML:Q4_K_M
Run and chat with the model
lemonade run user.Vistral-7B-ChatML-Q4_K_M
List all available models
lemonade list
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, HfArgumentParser, TrainingArguments, pipeline, logging, TextStreamer | |
| from peft import LoraConfig, PeftModel, prepare_model_for_kbit_training, get_peft_model | |
| import os, torch, wandb, platform, warnings | |
| from datasets import load_dataset | |
| from trl import SFTTrainer | |
| hf_token = '' | |
| wnb_token = '' | |
| wnb_name = 'vistral-chatml' | |
| MODEL = 'Viet-Mistral/Vistral-7B-Chat' | |
| resume_from_checkpoint = False | |
| output_dir = 'vistral-chatml' | |
| tokenizer_path = '.' | |
| ####################################################### | |
| ## DATASET | |
| from datasets import load_dataset | |
| def generate_system_prompt(i): | |
| system_prompt = "Bạn là một trợ lí Tiếng Việt nhiệt tình và trung thực. Hãy luôn trả lời một cách hữu ích nhất có thể, đồng thời giữ an toàn." | |
| if i % 2 == 0: | |
| system_prompt += "\nCâu trả lời của bạn không nên chứa bất kỳ nội dung gây hại, phân biệt chủng tộc, phân biệt giới tính, độc hại, nguy hiểm hoặc bất hợp pháp nào. Hãy đảm bảo rằng các câu trả lời của bạn không có thiên kiến xã hội và mang tính tích cực." | |
| if i % 5 == 0: | |
| system_prompt += "\nNếu một câu hỏi không có ý nghĩa hoặc không hợp lý về mặt thông tin, hãy giải thích tại sao thay vì trả lời một điều gì đó không chính xác. Nếu bạn không biết câu trả lời cho một câu hỏi, hãy trẳ lời là bạn không biết và vui lòng không chia sẻ thông tin sai lệch." | |
| return system_prompt | |
| tokenizer = AutoTokenizer.from_pretrained(tokenizer_path) | |
| def tokenize_chat(input, i): | |
| print(generate_system_prompt(i)) | |
| conversation = [{'role': 'system', 'content': generate_system_prompt(i)}] | |
| for msg in input['conversations']: | |
| output = {'role': 'user', 'content': msg['value']} | |
| if msg['from'] == 'gpt': | |
| output['role'] = 'assistant' | |
| conversation.append(output) | |
| formatted = tokenizer.apply_chat_template(conversation, tokenize=False) | |
| return tokenizer(formatted) | |
| sharegpt_dataset = load_dataset('bkai-foundation-models/vi-self-chat-sharegpt-format') | |
| train_data = sharegpt_dataset['train'].shuffle(seed=42)\ | |
| .select(range(800))\ | |
| .map(lambda x, i: tokenize_chat(x, i), remove_columns=["conversations"], with_indices=True) | |
| ####################################################### | |
| ## SETUP | |
| wandb.login(key=wnb_token) | |
| wandb.init(name=wnb_name) | |
| # use custom tokenizer instead of one comes from the model | |
| #tokenizer = AutoTokenizer.from_pretrained( | |
| # MODEL, | |
| # add_eos_token=False, | |
| # add_bos_token=False, | |
| # token=hf_token, | |
| #) | |
| bnb_config = BitsAndBytesConfig( | |
| load_in_4bit=True, | |
| bnb_4bit_quant_type="nf4", | |
| bnb_4bit_compute_dtype=torch.bfloat16, | |
| bnb_4bit_use_double_quant=True, | |
| ) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| MODEL, | |
| device_map="auto", | |
| token=hf_token, | |
| quantization_config=bnb_config, | |
| trust_remote_code=True, | |
| ) | |
| ####################################################### | |
| ## LORA CONFIG | |
| model.gradient_checkpointing_enable() | |
| model = prepare_model_for_kbit_training(model) | |
| peft_config = LoraConfig( | |
| r=8, | |
| lora_alpha=16, | |
| target_modules=[ | |
| "q_proj", | |
| "k_proj", | |
| "v_proj", | |
| "o_proj", | |
| "gate_proj", | |
| "up_proj", | |
| "down_proj", | |
| "lm_head", | |
| ], | |
| bias="none", | |
| lora_dropout=0.05, # Conventional | |
| task_type="CAUSAL_LM", | |
| ) | |
| model = get_peft_model(model, peft_config) | |
| model.print_trainable_parameters() | |
| from accelerate import Accelerator | |
| accelerator = Accelerator() | |
| model = accelerator.prepare_model(model) | |
| ####################################################### | |
| ## TRAIN | |
| from transformers import Trainer, TrainingArguments, DataCollatorForLanguageModeling | |
| trainer = Trainer( | |
| model=model, | |
| train_dataset=train_data, | |
| args=TrainingArguments( | |
| report_to='wandb', | |
| warmup_steps=1, | |
| per_device_train_batch_size=1, | |
| gradient_accumulation_steps=4, | |
| gradient_checkpointing=True, | |
| num_train_epochs=4, | |
| learning_rate=2.5e-5, | |
| logging_steps=1, | |
| optim="paged_adamw_8bit", | |
| save_strategy="steps", | |
| save_steps=10, | |
| save_total_limit=4, | |
| output_dir=output_dir | |
| ), | |
| data_collator=DataCollatorForLanguageModeling(tokenizer, mlm=False) | |
| ) | |
| model.config.use_cache = False | |
| trainer.train(resume_from_checkpoint=resume_from_checkpoint) | |