Instructions to use NgaNTQ/VinaLLaMA_LAWQA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NgaNTQ/VinaLLaMA_LAWQA with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="NgaNTQ/VinaLLaMA_LAWQA")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("NgaNTQ/VinaLLaMA_LAWQA") model = AutoModelForCausalLM.from_pretrained("NgaNTQ/VinaLLaMA_LAWQA", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use NgaNTQ/VinaLLaMA_LAWQA with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "NgaNTQ/VinaLLaMA_LAWQA" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NgaNTQ/VinaLLaMA_LAWQA", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/NgaNTQ/VinaLLaMA_LAWQA
- SGLang
How to use NgaNTQ/VinaLLaMA_LAWQA 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 "NgaNTQ/VinaLLaMA_LAWQA" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NgaNTQ/VinaLLaMA_LAWQA", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "NgaNTQ/VinaLLaMA_LAWQA" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NgaNTQ/VinaLLaMA_LAWQA", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use NgaNTQ/VinaLLaMA_LAWQA with Docker Model Runner:
docker model run hf.co/NgaNTQ/VinaLLaMA_LAWQA
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Load Model
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained("NgaNTQ/Law-Llama-v1", add_eos_token=True, padding_side='right')
model = AutoModelForCausalLM.from_pretrained(
'NgaNTQ/Law-Llama-v1',
torch_dtype=torch.bfloat16,
quantization_config=bnb_config, # If you need
device_map="auto",
use_cache=True,
)
tokenizer.pad_token = tokenizer.eos_token
Generate
PROMPT = """
### Hướng dẫn: Bạn là một trợ lí Tiếng Việt. Hãy luôn trả lời một cách trung thực và an toàn
Câu trả lời của bạn không nên chứa bất kỳ nội dung gây hại, nguy hiểm hoặc bất hợp pháp nào
Nế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.
### Câu hỏi: {input}
"""
question = """Trình bày về thủ tục li hôn ?"""
text = PROMPT.format_map({
'input': question,
})
input_ids = tokenizer(text, return_tensors='pt', add_special_tokens=False).to('cuda')
generated_ids = model.generate(
input_ids=input_ids['input_ids'],
max_new_tokens=1024,
do_sample=True,
top_p=0.95,
top_k=40,
temperature=0.3,
repetition_penalty=1.1,
no_repeat_ngram_size=7,
num_beams=5,
)
a = tokenizer.batch_decode(generated_ids)[0]
# print(a.split('### Trả lời:')[1])
print(a)
- Downloads last month
- 8