Text Generation
Transformers
Safetensors
Portuguese
llama
Portuguese
Tiny-Llama
PEFT
conversational
text-generation-inference
Instructions to use lrds-code/samba-1.1B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lrds-code/samba-1.1B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lrds-code/samba-1.1B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("lrds-code/samba-1.1B") model = AutoModelForCausalLM.from_pretrained("lrds-code/samba-1.1B") 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 lrds-code/samba-1.1B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lrds-code/samba-1.1B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lrds-code/samba-1.1B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/lrds-code/samba-1.1B
- SGLang
How to use lrds-code/samba-1.1B 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 "lrds-code/samba-1.1B" \ --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": "lrds-code/samba-1.1B", "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 "lrds-code/samba-1.1B" \ --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": "lrds-code/samba-1.1B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use lrds-code/samba-1.1B with Docker Model Runner:
docker model run hf.co/lrds-code/samba-1.1B
Update README.md
Browse files
README.md
CHANGED
|
@@ -41,8 +41,6 @@ Samba é um LLM treinado em dados da língua portuguesa. O modelo é baseado no
|
|
| 41 |
|
| 42 |
## Como usar
|
| 43 |
|
| 44 |
-
Com o `transformers pipeline`:
|
| 45 |
-
|
| 46 |
```python
|
| 47 |
import torch
|
| 48 |
from transformers import pipeline
|
|
@@ -59,51 +57,6 @@ outputs = samba(prompt, max_new_tokens=256, do_sample=False, temperature=0.1, to
|
|
| 59 |
print(outputs[0]['generated_text'])
|
| 60 |
```
|
| 61 |
|
| 62 |
-
Com o `transformers AutoModel`
|
| 63 |
-
|
| 64 |
-
```python
|
| 65 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
| 66 |
-
|
| 67 |
-
def GeneratePrompt(input, instruction):
|
| 68 |
-
if input!='' and instruction!=0:
|
| 69 |
-
return f'''Abaixo está uma instrução que descreve uma tarefa, juntamente com uma entrada que fornece mais contexto. Escreva uma resposta que complete adequadamente o pedido.
|
| 70 |
-
### Instrução
|
| 71 |
-
{instruction}
|
| 72 |
-
### Entrada
|
| 73 |
-
{input}'''
|
| 74 |
-
else:
|
| 75 |
-
return f'''Abaixo está uma instrução que descreve uma tarefa, juntamente com uma entrada que fornece mais contexto. Escreva uma resposta que complete adequadamente o pedido.
|
| 76 |
-
### Instrução
|
| 77 |
-
{instruction}
|
| 78 |
-
### Entrada'''
|
| 79 |
-
|
| 80 |
-
model_config = GenerationConfig.from_model_config(model.generation_config)
|
| 81 |
-
model.generation_config.temperature = 0.1
|
| 82 |
-
|
| 83 |
-
model = AutoModelForCausalLM.from_pretrained('lrds-code/samba-1.1B')
|
| 84 |
-
tokenizer = AutoTokenizer.from_pretrained('lrds-code/samba-1.1B')
|
| 85 |
-
|
| 86 |
-
instruction = 'Quantos planetas existem no sistema solar?'
|
| 87 |
-
text = GeneratePrompt(input='', instruction=instruction)
|
| 88 |
-
inputs = tokenizer(text, return_tensors='pt')
|
| 89 |
-
outputs = model.generate(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'], generation_config=model_config, repetition_penalty=1.1, do_sample=False)
|
| 90 |
-
print(outputs[0]['generated_text'])
|
| 91 |
-
```
|
| 92 |
-
|
| 93 |
-
## Prompt para Finetune
|
| 94 |
-
|
| 95 |
-
Para o finetune do Samba utilizamos o template [Alpaca](https://huggingface.co/datasets/yahma/alpaca-cleaned).
|
| 96 |
-
|
| 97 |
-
```python
|
| 98 |
-
alpaca_prompt = f'''Abaixo está uma instrução que descreve uma tarefa, juntamente com uma entrada que fornece mais contexto. Escreva uma resposta que complete adequadamente o pedido.
|
| 99 |
-
### Instrução
|
| 100 |
-
{instruction}
|
| 101 |
-
### Entrada
|
| 102 |
-
{input}
|
| 103 |
-
### Resposta
|
| 104 |
-
{output}'''
|
| 105 |
-
```
|
| 106 |
-
|
| 107 |
## Parâmetros Importantes
|
| 108 |
|
| 109 |
- **repetition_penalty:** é utilizado para evitar a repetição de palavras ou frases. Quando esse valor é ajustado para ser maior que 1, o modelo tenta diminuir a probabilidade de gerar palavras que já apareceram anteriormente. Basicamente, quanto maior o valor, mais o modelo tenta evitar repetições.
|
|
|
|
| 41 |
|
| 42 |
## Como usar
|
| 43 |
|
|
|
|
|
|
|
| 44 |
```python
|
| 45 |
import torch
|
| 46 |
from transformers import pipeline
|
|
|
|
| 57 |
print(outputs[0]['generated_text'])
|
| 58 |
```
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
## Parâmetros Importantes
|
| 61 |
|
| 62 |
- **repetition_penalty:** é utilizado para evitar a repetição de palavras ou frases. Quando esse valor é ajustado para ser maior que 1, o modelo tenta diminuir a probabilidade de gerar palavras que já apareceram anteriormente. Basicamente, quanto maior o valor, mais o modelo tenta evitar repetições.
|