Instructions to use JuliaKreutzerCohere/tiny-aya-global-prompt with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use JuliaKreutzerCohere/tiny-aya-global-prompt with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="JuliaKreutzerCohere/tiny-aya-global-prompt") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("JuliaKreutzerCohere/tiny-aya-global-prompt") model = AutoModelForCausalLM.from_pretrained("JuliaKreutzerCohere/tiny-aya-global-prompt", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use JuliaKreutzerCohere/tiny-aya-global-prompt with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "JuliaKreutzerCohere/tiny-aya-global-prompt" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "JuliaKreutzerCohere/tiny-aya-global-prompt", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/JuliaKreutzerCohere/tiny-aya-global-prompt
- SGLang
How to use JuliaKreutzerCohere/tiny-aya-global-prompt 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 "JuliaKreutzerCohere/tiny-aya-global-prompt" \ --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": "JuliaKreutzerCohere/tiny-aya-global-prompt", "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 "JuliaKreutzerCohere/tiny-aya-global-prompt" \ --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": "JuliaKreutzerCohere/tiny-aya-global-prompt", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use JuliaKreutzerCohere/tiny-aya-global-prompt with Docker Model Runner:
docker model run hf.co/JuliaKreutzerCohere/tiny-aya-global-prompt
Upload script.py with huggingface_hub
Browse files
script.py
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import re
|
|
|
|
| 3 |
import json
|
| 4 |
-
import pandas as pd
|
| 5 |
import torch
|
| 6 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 7 |
|
|
@@ -46,10 +66,11 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 46 |
MODEL_ID, torch_dtype=torch.float16, device_map="auto"
|
| 47 |
).eval()
|
| 48 |
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
outputs_queries_types = []
|
| 52 |
-
for
|
| 53 |
|
| 54 |
# Create the prompt.
|
| 55 |
messages = [
|
|
@@ -81,7 +102,7 @@ for _, r in df.iterrows():
|
|
| 81 |
done = True
|
| 82 |
|
| 83 |
outputs_queries_types.append((text, r['id'], r['query'], r['task_type']))
|
| 84 |
-
print(f"{len(outputs_queries_types)}/{len(
|
| 85 |
|
| 86 |
# Postprocess and store the answers.
|
| 87 |
def expected_answer_count(query: str, task_type: str) -> int:
|
|
@@ -200,5 +221,8 @@ rows = []
|
|
| 200 |
for answer, row_id, query, task_type in outputs_queries_types:
|
| 201 |
answers = postprocess_answer(answer, query, task_type)
|
| 202 |
rows.append({"id": row_id, "pred": json.dumps(answers, ensure_ascii=False)})
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
| 204 |
print("wrote submission.csv", flush=True)
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
# Eval sandbox ships older transformers/tokenizers; tiny-aya needs recent versions.
|
| 5 |
+
# Pip has network even though model loading is offline.
|
| 6 |
+
subprocess.run(
|
| 7 |
+
[
|
| 8 |
+
sys.executable,
|
| 9 |
+
"-m",
|
| 10 |
+
"pip",
|
| 11 |
+
"install",
|
| 12 |
+
"-q",
|
| 13 |
+
"transformers>=4.56",
|
| 14 |
+
"tokenizers>=0.21.1",
|
| 15 |
+
"accelerate>=0.30",
|
| 16 |
+
"torch>=2.2",
|
| 17 |
+
],
|
| 18 |
+
check=True,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
import os
|
| 22 |
import re
|
| 23 |
+
import csv
|
| 24 |
import json
|
|
|
|
| 25 |
import torch
|
| 26 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 27 |
|
|
|
|
| 66 |
MODEL_ID, torch_dtype=torch.float16, device_map="auto"
|
| 67 |
).eval()
|
| 68 |
|
| 69 |
+
with open("/tmp/data/test.csv", encoding="utf-8", newline="") as f:
|
| 70 |
+
test_rows = list(csv.DictReader(f))
|
| 71 |
|
| 72 |
outputs_queries_types = []
|
| 73 |
+
for r in test_rows:
|
| 74 |
|
| 75 |
# Create the prompt.
|
| 76 |
messages = [
|
|
|
|
| 102 |
done = True
|
| 103 |
|
| 104 |
outputs_queries_types.append((text, r['id'], r['query'], r['task_type']))
|
| 105 |
+
print(f"{len(outputs_queries_types)}/{len(test_rows)} done", flush=True)
|
| 106 |
|
| 107 |
# Postprocess and store the answers.
|
| 108 |
def expected_answer_count(query: str, task_type: str) -> int:
|
|
|
|
| 221 |
for answer, row_id, query, task_type in outputs_queries_types:
|
| 222 |
answers = postprocess_answer(answer, query, task_type)
|
| 223 |
rows.append({"id": row_id, "pred": json.dumps(answers, ensure_ascii=False)})
|
| 224 |
+
with open("submission.csv", "w", encoding="utf-8", newline="") as f:
|
| 225 |
+
writer = csv.DictWriter(f, fieldnames=["id", "pred"])
|
| 226 |
+
writer.writeheader()
|
| 227 |
+
writer.writerows(rows)
|
| 228 |
print("wrote submission.csv", flush=True)
|