Instructions to use duyntnet/Megrez-3B-Instruct-imatrix-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use duyntnet/Megrez-3B-Instruct-imatrix-GGUF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="duyntnet/Megrez-3B-Instruct-imatrix-GGUF") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("duyntnet/Megrez-3B-Instruct-imatrix-GGUF", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use duyntnet/Megrez-3B-Instruct-imatrix-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf duyntnet/Megrez-3B-Instruct-imatrix-GGUF: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 duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf duyntnet/Megrez-3B-Instruct-imatrix-GGUF: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 duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M
Use Docker
docker model run hf.co/duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use duyntnet/Megrez-3B-Instruct-imatrix-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "duyntnet/Megrez-3B-Instruct-imatrix-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "duyntnet/Megrez-3B-Instruct-imatrix-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M
- SGLang
How to use duyntnet/Megrez-3B-Instruct-imatrix-GGUF 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 "duyntnet/Megrez-3B-Instruct-imatrix-GGUF" \ --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": "duyntnet/Megrez-3B-Instruct-imatrix-GGUF", "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 "duyntnet/Megrez-3B-Instruct-imatrix-GGUF" \ --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": "duyntnet/Megrez-3B-Instruct-imatrix-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use duyntnet/Megrez-3B-Instruct-imatrix-GGUF with Ollama:
ollama run hf.co/duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M
- Unsloth Studio
How to use duyntnet/Megrez-3B-Instruct-imatrix-GGUF 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 duyntnet/Megrez-3B-Instruct-imatrix-GGUF 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 duyntnet/Megrez-3B-Instruct-imatrix-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for duyntnet/Megrez-3B-Instruct-imatrix-GGUF to start chatting
- Docker Model Runner
How to use duyntnet/Megrez-3B-Instruct-imatrix-GGUF with Docker Model Runner:
docker model run hf.co/duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M
- Lemonade
How to use duyntnet/Megrez-3B-Instruct-imatrix-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull duyntnet/Megrez-3B-Instruct-imatrix-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.Megrez-3B-Instruct-imatrix-GGUF-Q4_K_M
List all available models
lemonade list
- Atomic Chat
Quantizations of https://huggingface.co/Infinigence/Megrez-3B-Instruct
Note: you will need llama.cpp b4381 or later to run the model.
Inference Clients/UIs
From original readme
Megrez-3B-Instruct is a large language model trained by Infinigence AI. Megrez-3B aims to provide a fast inference, compact, and powerful edge-side intelligent solution through software-hardware co-design. Megrez-3B has the following advantages:
- High Accuracy: Megrez-3B successfully compresses the capabilities of the previous 14 billion model into a 3 billion size, and achieves excellent performance on mainstream benchmarks.
- High Speed: A smaller model does not necessarily bring faster speed. Megrez-3B ensures a high degree of compatibility with mainstream hardware through software-hardware co-design, leading an inference speedup up to 300% compared to previous models of the same accuracy.
- Easy to Use: In the beginning, we had a debate about model design: should we design a unique but efficient model structure, or use a classic structure for ease of use? We chose the latter and adopt the most primitive LLaMA structure, which allows developers to deploy the model on various platforms without any modifications and minimize the complexity of future development.
- Rich Applications: We have provided a fullstack WebSearch solution. Our model is functionally trained on web search tasks, enabling it to automatically determine the timing of search invocations and provide better summarization results. The complete deployment code is released on github.
Inference Parameters
- For chat, text generation, and other tasks that benefit from diversity, we recommend to use the inference parameter temperature=0.7.
- For mathematical and reasoning tasks, we recommend to use the inference parameter temperature=0.2 for better determinacy.
Huggingface
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
path = "Infinigence/Megrez-3B-Instruct"
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)
messages = [
{"role": "user", "content": "How to make braised chicken in brown sauce?"},
]
model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(device)
model_outputs = model.generate(
model_inputs,
do_sample=True,
max_new_tokens=1024,
top_p=0.9,
temperature=0.2
)
output_token_ids = [
model_outputs[i][len(model_inputs[i]):] for i in range(len(model_inputs))
]
responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0]
print(responses)
vLLM Inference
- Installation
# Install vLLM with CUDA 12.1.
pip install vllm
- Example code
python inference/inference_vllm.py --model_path <hf_repo_path> --prompt_path prompts/prompt_demo.txt
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams
model_name = "Infinigence/Megrez-3B-Instruct"
prompt = [{"role": "user", "content": "How to make braised chicken in brown sauce?"}]
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
input_text = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
llm = LLM(
model=model_name,
trust_remote_code=True,
tensor_parallel_size=1
)
sampling_params = SamplingParams(top_p=0.9, temperature=0.2, max_tokens=1024, repetition_penalty=1.02)
outputs = llm.generate(prompts=input_text, sampling_params=sampling_params)
print(outputs[0].outputs[0].text)
- Downloads last month
- 27
1-bit
2-bit
3-bit
4-bit
5-bit
6-bit
8-bit