Instructions to use mlabonne/AlphaMonarch-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mlabonne/AlphaMonarch-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mlabonne/AlphaMonarch-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mlabonne/AlphaMonarch-7B") model = AutoModelForCausalLM.from_pretrained("mlabonne/AlphaMonarch-7B") 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]:])) - Inference
- Local Apps Settings
- vLLM
How to use mlabonne/AlphaMonarch-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mlabonne/AlphaMonarch-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlabonne/AlphaMonarch-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mlabonne/AlphaMonarch-7B
- SGLang
How to use mlabonne/AlphaMonarch-7B 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 "mlabonne/AlphaMonarch-7B" \ --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": "mlabonne/AlphaMonarch-7B", "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 "mlabonne/AlphaMonarch-7B" \ --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": "mlabonne/AlphaMonarch-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use mlabonne/AlphaMonarch-7B with Docker Model Runner:
docker model run hf.co/mlabonne/AlphaMonarch-7B
The tokenizer has two ids for the same token
I'm loading a HF tokenizer, and wanted to stop on the sequence "</|im_end|>", but it looks like the tokenizer has 2 different ids for the same token, is it a bug or supposed to be so?
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("LoneStriker/AlphaMonarch-7B-AWQ", device_map='cuda')
model = AutoModelForCausalLM.from_pretrained("LoneStriker/AlphaMonarch-7B-AWQ", device_map='cuda')
tokenizer.decode(700) # '</'
tokenizer.decode(1867) # '</'
tokenizer.decode(700) == tokenizer.decode(1867)
Hmm I've never encountered that before, it's quite strange. The tokenizer should be Mistral/Llama. You don't have the same issue with base models?
So it turns out, that the encoding depends on the position in the sentence
https://stackoverflow.com/questions/78039649/huggingface-tokenizer-has-two-ids-for-the-same-token/78039999#78039999
I was also surprised to see generation end with</|im_end|>, as ChatML mentions only <|im_end|> (without a slash).
https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/ai-services/openai/includes/chat-markup-language.md
BTW, I see that sometimes the model does generate <|im_end|> and also the Russian version <|им_начало|>user and <|им_конец|>.
I ended-up writing custom code to check the stop sequence.
self.chevron_slash_stop_token_ids = [tensor(700).cuda(), tensor(1867).cuda()]
# Could be used for <|im_end|> and also other languages. E.g., the Russian version <|им_конец|>
self.chevron_pipe_token_sequence = tokenizer.encode("<|", add_special_tokens=False, return_tensors='pt').cuda()[0]
self.stopping_criteria = StoppingCriteriaList([self.custom_stopping_criteria])
def custom_stopping_criteria(self, input_ids: torch.LongTensor, _, **__) -> bool:
# Check if the last token matches the stop tokens </
if input_ids[0][-1].equal(self.chevron_slash_stop_token_ids[0]) or input_ids[0][-1].equal(
self.chevron_slash_stop_token_ids[1]):
return True
# Check if the last tokens match the sequence for <|
if input_ids[0][-len(self.chevron_pipe_token_sequence):].equal(self.chevron_pipe_token_sequence):
return True
return False