Instructions to use Britania/m2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Britania/m2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Britania/m2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Britania/m2") model = AutoModelForCausalLM.from_pretrained("Britania/m2", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Britania/m2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Britania/m2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Britania/m2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Britania/m2
- SGLang
How to use Britania/m2 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 "Britania/m2" \ --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": "Britania/m2", "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 "Britania/m2" \ --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": "Britania/m2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Britania/m2 with Docker Model Runner:
docker model run hf.co/Britania/m2
Update handler.py
Browse files- handler.py +9 -1
handler.py
CHANGED
|
@@ -3,6 +3,12 @@ from typing import Dict, Any, List
|
|
| 3 |
import torch
|
| 4 |
import json
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
class EndpointHandler():
|
| 7 |
def __init__(self, path=""):
|
| 8 |
# Carga el modelo y el tokenizer
|
|
@@ -17,7 +23,9 @@ class EndpointHandler():
|
|
| 17 |
|
| 18 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 19 |
# Procesa la entrada y llama al modelo para generar texto
|
| 20 |
-
input_data =
|
|
|
|
|
|
|
| 21 |
template = """
|
| 22 |
[INST] <<SYS>>
|
| 23 |
A continuaci贸n se presentan par谩metros fisiol贸gicos y ambientales capturados por los sensores de un smartwatch utilizado por un atleta. Bas谩ndote en estos datos y en tu conocimiento de las rutinas de entrenamiento para atletas, crea una rutina diaria de entrenamiento personalizada para el atleta.
|
|
|
|
| 3 |
import torch
|
| 4 |
import json
|
| 5 |
|
| 6 |
+
def model_inference(model, tokenizer, text, max_new_tokens, temperature):
|
| 7 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 8 |
+
with torch.inference_mode():
|
| 9 |
+
outputs = model.generate(**inputs, max_new_tokens=max_new_tokens, temperature=temperature)
|
| 10 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 11 |
+
|
| 12 |
class EndpointHandler():
|
| 13 |
def __init__(self, path=""):
|
| 14 |
# Carga el modelo y el tokenizer
|
|
|
|
| 23 |
|
| 24 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 25 |
# Procesa la entrada y llama al modelo para generar texto
|
| 26 |
+
input_data = {}
|
| 27 |
+
for key, value in data.items():
|
| 28 |
+
input_data[key] = value
|
| 29 |
template = """
|
| 30 |
[INST] <<SYS>>
|
| 31 |
A continuaci贸n se presentan par谩metros fisiol贸gicos y ambientales capturados por los sensores de un smartwatch utilizado por un atleta. Bas谩ndote en estos datos y en tu conocimiento de las rutinas de entrenamiento para atletas, crea una rutina diaria de entrenamiento personalizada para el atleta.
|