Instructions to use Dorjzodovsuren/Mongolian_Llama3-v1.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Dorjzodovsuren/Mongolian_Llama3-v1.1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Dorjzodovsuren/Mongolian_Llama3-v1.1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Dorjzodovsuren/Mongolian_Llama3-v1.1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Dorjzodovsuren/Mongolian_Llama3-v1.1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Dorjzodovsuren/Mongolian_Llama3-v1.1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Dorjzodovsuren/Mongolian_Llama3-v1.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Dorjzodovsuren/Mongolian_Llama3-v1.1
- SGLang
How to use Dorjzodovsuren/Mongolian_Llama3-v1.1 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 "Dorjzodovsuren/Mongolian_Llama3-v1.1" \ --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": "Dorjzodovsuren/Mongolian_Llama3-v1.1", "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 "Dorjzodovsuren/Mongolian_Llama3-v1.1" \ --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": "Dorjzodovsuren/Mongolian_Llama3-v1.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use Dorjzodovsuren/Mongolian_Llama3-v1.1 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 Dorjzodovsuren/Mongolian_Llama3-v1.1 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 Dorjzodovsuren/Mongolian_Llama3-v1.1 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for Dorjzodovsuren/Mongolian_Llama3-v1.1 to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="Dorjzodovsuren/Mongolian_Llama3-v1.1", max_seq_length=2048, ) - Docker Model Runner
How to use Dorjzodovsuren/Mongolian_Llama3-v1.1 with Docker Model Runner:
docker model run hf.co/Dorjzodovsuren/Mongolian_Llama3-v1.1
Mongolian-Llama3.1
Model Description
To implement Mongolian-Llama3.1 in a Chat UI, you'll need to set up an interface that interacts with the Llama 3.1 model. Here’s a step-by-step guide to achieve this:
Mongolian-Llama3.1 is the second open source instruction-tuned language model for Mongolian & English users with various abilities such as roleplaying & tool-using built upon the quantized Meta-Llama-3.1-8B model.
Developed by: Dorjzodovsuren
License: Llama-3 License
Base Model: llama-3.1-8b-bnb-4bit
Model Size: 4.65B
Context length: 8K
Bias, Risks, and Limitations
To combat fake news, current strategies rely heavily on synthetic and translated data. However, these approaches have inherent biases, risks, and limitations:
Synthetic Data Bias: Algorithms may inadvertently perpetuate biases present in training data.
Translation Inaccuracy: Translations can distort meaning or lose context, leading to misinformation.
Cultural Nuances: Synthetic and translated data may miss cultural intricacies, risking amplification of stereotypes.
Algorithmic Limits: Effectiveness is constrained by algorithm capabilities and training data quality.
Dependency on Data: Accuracy hinges on quality and representativeness of training data.
Adversarial Attacks: Malicious actors can exploit vulnerabilities to manipulate content.
Different answer based on language: Answer might be a bit different based on language.
Recommendations
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. Due to hallucinations and pretraining datasets characteristics, some information might be misleading, and answer might be a bit different based on language.
Please ask in Mongolian if possible.
Disclaimer:
We are not responsible for any consequences resulting from the use of this model or the outputs it generates. Users are advised to employ the model's predictions with caution and to independently verify the information provided.
How to Get Started with the Model
Use the code below to get started with the model.
import torch
import gradio as gr
from threading import Thread
from unsloth import FastLanguageModel
from transformers import TextStreamer
from transformers import AutoModelForCausalLM, AutoTokenizer, StoppingCriteria, StoppingCriteriaList, TextIteratorStreamer
max_seq_length = 2048
load_in_4bit = True
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "Dorjzodovsuren/Mongolian_Llama3-v1.1",
max_seq_length = max_seq_length,
dtype = None,
load_in_4bit = load_in_4bit,
)
EOS_TOKEN = tokenizer.eos_token # Must add EOS_TOKEN
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""
# Enable native 2x faster inference
FastLanguageModel.for_inference(model)
# Create a text streamer
text_streamer = TextStreamer(tokenizer, skip_prompt=False,skip_special_tokens=True)
# Get the device based on GPU availability
device = 'cuda' if torch.cuda.is_available() else 'cpu'
# Move model into device
model = model.to(device)
class StopOnTokens(StoppingCriteria):
def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
stop_ids = [29, 0]
for stop_id in stop_ids:
if input_ids[0][-1] == stop_id:
return True
return False
# Current implementation does not support conversation based on history.
# Highly recommend to experiment on various hyper parameters to compare qualities.
def predict(message, history):
stop = StopOnTokens()
messages = alpaca_prompt.format(
message,
"",
"",
)
model_inputs = tokenizer([messages], return_tensors="pt").to(device)
streamer = TextIteratorStreamer(tokenizer, timeout=10., skip_prompt=True, skip_special_tokens=True)
generate_kwargs = dict(
model_inputs,
streamer=streamer,
max_new_tokens=max_seq_length,
temperature=0.7,
top_p=0.9,
top_k=50,
do_sample=True,
stopping_criteria=StoppingCriteriaList([stop])
)
t = Thread(target=model.generate, kwargs=generate_kwargs)
t.start()
partial_message = ""
for new_token in streamer:
if new_token != '<':
partial_message += new_token
yield partial_message
gr.ChatInterface(predict).launch(debug=True, share=True, show_api=True)
