Text Generation
Transformers
English
qwen2
code-generation
python
fine-tuning
Qwen
tools
agent-framework
multi-agent
conversational
Eval Results (legacy)
Instructions to use my-ai-stack/Stack-2-9-finetuned with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use my-ai-stack/Stack-2-9-finetuned with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="my-ai-stack/Stack-2-9-finetuned") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("my-ai-stack/Stack-2-9-finetuned") model = AutoModelForCausalLM.from_pretrained("my-ai-stack/Stack-2-9-finetuned") 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
- vLLM
How to use my-ai-stack/Stack-2-9-finetuned with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "my-ai-stack/Stack-2-9-finetuned" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/my-ai-stack/Stack-2-9-finetuned
- SGLang
How to use my-ai-stack/Stack-2-9-finetuned 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 "my-ai-stack/Stack-2-9-finetuned" \ --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": "my-ai-stack/Stack-2-9-finetuned", "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 "my-ai-stack/Stack-2-9-finetuned" \ --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": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use my-ai-stack/Stack-2-9-finetuned with Docker Model Runner:
docker model run hf.co/my-ai-stack/Stack-2-9-finetuned
walidsobhie-code commited on
Commit ·
7a8afa9
1
Parent(s): 4ca507e
Add interactive chat script with improved generation settings
Browse files
chat.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
print("Loading your fine-tuned Stack 2.9 model...")
|
| 5 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 6 |
+
'/Users/walidsobhi/stack-2-9-final-model',
|
| 7 |
+
torch_dtype=torch.float16,
|
| 8 |
+
device_map='auto'
|
| 9 |
+
)
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained('/Users/walidsobhi/stack-2-9-final-model')
|
| 11 |
+
print("✅ Ready!\n")
|
| 12 |
+
|
| 13 |
+
# Generation settings
|
| 14 |
+
MAX_TOKENS = 150
|
| 15 |
+
TEMPERATURE = 0.3
|
| 16 |
+
TOP_P = 0.9
|
| 17 |
+
REP_PENALTY = 1.2
|
| 18 |
+
|
| 19 |
+
print(f"Settings: max_tokens={MAX_TOKENS}, temperature={TEMPERATURE}, top_p={TOP_P}\n")
|
| 20 |
+
|
| 21 |
+
# Interactive loop
|
| 22 |
+
while True:
|
| 23 |
+
try:
|
| 24 |
+
prompt = input("You: ")
|
| 25 |
+
if prompt.lower() in ['quit', 'exit', 'q']:
|
| 26 |
+
break
|
| 27 |
+
if not prompt.strip():
|
| 28 |
+
continue
|
| 29 |
+
|
| 30 |
+
inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
|
| 31 |
+
outputs = model.generate(
|
| 32 |
+
**inputs,
|
| 33 |
+
max_new_tokens=MAX_TOKENS,
|
| 34 |
+
temperature=TEMPERATURE,
|
| 35 |
+
top_p=TOP_P,
|
| 36 |
+
repetition_penalty=REP_PENALTY,
|
| 37 |
+
do_sample=True,
|
| 38 |
+
pad_token_id=tokenizer.eos_token_id
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Extract only the new tokens (skip the prompt)
|
| 42 |
+
full_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 43 |
+
response = full_response[len(prompt):].strip()
|
| 44 |
+
|
| 45 |
+
# Stop at common stop points
|
| 46 |
+
for stop in ['\n\n\n', 'You:', 'AI:', 'User:', 'Assistant:']:
|
| 47 |
+
if stop in response:
|
| 48 |
+
response = response.split(stop)[0].strip()
|
| 49 |
+
|
| 50 |
+
print(f"AI: {response}\n")
|
| 51 |
+
|
| 52 |
+
except KeyboardInterrupt:
|
| 53 |
+
print("\nExiting...")
|
| 54 |
+
break
|
| 55 |
+
|
| 56 |
+
print("Goodbye!")
|