Text Generation
Transformers
ONNX
Safetensors
Italian
gpt2
DAC
DATA-AI
data-ai
conversational
text-generation-inference
Instructions to use Mattimax/DACMini-IT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Mattimax/DACMini-IT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Mattimax/DACMini-IT") 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("Mattimax/DACMini-IT") model = AutoModelForCausalLM.from_pretrained("Mattimax/DACMini-IT", 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 Mattimax/DACMini-IT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Mattimax/DACMini-IT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Mattimax/DACMini-IT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Mattimax/DACMini-IT
- SGLang
How to use Mattimax/DACMini-IT 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 "Mattimax/DACMini-IT" \ --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": "Mattimax/DACMini-IT", "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 "Mattimax/DACMini-IT" \ --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": "Mattimax/DACMini-IT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Mattimax/DACMini-IT with Docker Model Runner:
docker model run hf.co/Mattimax/DACMini-IT
Update README.md
Browse files
README.md
CHANGED
|
@@ -79,6 +79,52 @@ Addestrato su **Mattimax/DATA-AI_Conversation_ITA**, un dataset italiano di dial
|
|
| 79 |
|
| 80 |
---
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
## Referenze
|
| 83 |
|
| 84 |
* Dataset: [Mattimax/DATA-AI_Conversation_ITA](https://huggingface.co/datasets/Mattimax/DATA-AI_Conversation_ITA)
|
|
|
|
| 79 |
|
| 80 |
---
|
| 81 |
|
| 82 |
+
## Codice per inferenza di esempio
|
| 83 |
+
|
| 84 |
+
```python
|
| 85 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 86 |
+
import torch
|
| 87 |
+
|
| 88 |
+
# 1. Carica modello e tokenizer addestrati
|
| 89 |
+
model_path = "Mattimax/DACMini-IT"
|
| 90 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 91 |
+
model = AutoModelForCausalLM.from_pretrained(model_path)
|
| 92 |
+
model.eval()
|
| 93 |
+
|
| 94 |
+
# 2. Funzione di generazione
|
| 95 |
+
def chat_inference(prompt, max_new_tokens=150, temperature=0.7, top_p=0.9):
|
| 96 |
+
# Costruisci input nel formato usato in training
|
| 97 |
+
formatted_prompt = f"<|user|> {prompt.strip()} <|assistant|>"
|
| 98 |
+
|
| 99 |
+
# Tokenizza
|
| 100 |
+
inputs = tokenizer(formatted_prompt, return_tensors="pt")
|
| 101 |
+
|
| 102 |
+
# Genera risposta
|
| 103 |
+
with torch.no_grad():
|
| 104 |
+
output = model.generate(
|
| 105 |
+
**inputs,
|
| 106 |
+
max_new_tokens=max_new_tokens,
|
| 107 |
+
temperature=temperature,
|
| 108 |
+
top_p=top_p,
|
| 109 |
+
do_sample=True,
|
| 110 |
+
pad_token_id=tokenizer.pad_token_id or tokenizer.eos_token_id
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# Decodifica e rimuovi prompt iniziale
|
| 114 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 115 |
+
response = generated_text.split("<|assistant|>")[-1].strip()
|
| 116 |
+
return response
|
| 117 |
+
|
| 118 |
+
# 3. Esempio d’uso
|
| 119 |
+
if __name__ == "__main__":
|
| 120 |
+
while True:
|
| 121 |
+
user_input = input("👤 Utente: ")
|
| 122 |
+
if user_input.lower() in ["exit", "quit"]:
|
| 123 |
+
break
|
| 124 |
+
response = chat_inference(user_input)
|
| 125 |
+
print(f"🤖 Assistant: {response}\n")
|
| 126 |
+
````
|
| 127 |
+
|
| 128 |
## Referenze
|
| 129 |
|
| 130 |
* Dataset: [Mattimax/DATA-AI_Conversation_ITA](https://huggingface.co/datasets/Mattimax/DATA-AI_Conversation_ITA)
|