Instructions to use tans37/mistral-query-router with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use tans37/mistral-query-router with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3") model = PeftModel.from_pretrained(base_model, "tans37/mistral-query-router") - Transformers
How to use tans37/mistral-query-router with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tans37/mistral-query-router") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("tans37/mistral-query-router", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tans37/mistral-query-router with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tans37/mistral-query-router" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tans37/mistral-query-router", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tans37/mistral-query-router
- SGLang
How to use tans37/mistral-query-router 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 "tans37/mistral-query-router" \ --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": "tans37/mistral-query-router", "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 "tans37/mistral-query-router" \ --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": "tans37/mistral-query-router", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tans37/mistral-query-router with Docker Model Runner:
docker model run hf.co/tans37/mistral-query-router
Download handler.py from tans37/mistral-query-router: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/tans37/mistral-query-router/resolve/main/handler.py
- Command line
-
hf download hf://tans37/mistral-query-router/handler.py
-
curl -L -o handler.py https://huggingface.co/tans37/mistral-query-router/resolve/main/handler.py
2.07 kB
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| from peft import PeftModel | |
| import json | |
| # Configuration | |
| BASE_MODEL = "mistralai/Mistral-7B-Instruct-v0.3" | |
| ADAPTER = "tans37/mistral-query-router" | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| # Load the base model and tokenizer | |
| self.tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL) | |
| # Load base model in half precision for efficiency | |
| base_model = AutoModelForCausalLM.from_pretrained( | |
| BASE_MODEL, | |
| torch_dtype=torch.float16, | |
| device_map="auto" | |
| ) | |
| # Load the Peft adapter | |
| # 'path' is the directory where the handler is located (the adapter repo) | |
| self.model = PeftModel.from_pretrained(base_model, path) | |
| self.model.eval() | |
| print(f"[Handler] Loaded LoRA adapter from {path} onto {BASE_MODEL}") | |
| def __call__(self, data): | |
| """ | |
| Args: | |
| data (:obj: `dict`): | |
| subset of the request body with the following keys: | |
| - `inputs`: the prompt to be processed | |
| - `parameters`: optional generation parameters | |
| """ | |
| inputs = data.pop("inputs", data) | |
| parameters = data.pop("parameters", { | |
| "max_new_tokens": 128, | |
| "temperature": 0.1, | |
| "top_p": 0.9, | |
| "do_sample": False | |
| }) | |
| # Tokenize | |
| inputs = self.tokenizer(inputs, return_tensors="pt").to(self.model.device) | |
| # Generate | |
| with torch.no_grad(): | |
| output_tokens = self.model.generate( | |
| **inputs, | |
| **parameters | |
| ) | |
| # Decode | |
| # We only want the new tokens, so we slice the output | |
| input_len = inputs["input_ids"].shape[1] | |
| new_tokens = output_tokens[0][input_len:] | |
| prediction = self.tokenizer.decode(new_tokens, skip_special_tokens=True) | |
| return [{"generated_text": prediction}] | |