Text Generation
Safetensors
Transformers
Portuguese
bitsandbytes
bnb
text_generation
portuguese
portuguese-portugal
amalia
inference
eu-pt
llm
Instructions to use EliezerCarvalho/AMALIA-9B-0626-SFT-bnb with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use EliezerCarvalho/AMALIA-9B-0626-SFT-bnb with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="EliezerCarvalho/AMALIA-9B-0626-SFT-bnb")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("EliezerCarvalho/AMALIA-9B-0626-SFT-bnb", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use EliezerCarvalho/AMALIA-9B-0626-SFT-bnb with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "EliezerCarvalho/AMALIA-9B-0626-SFT-bnb" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EliezerCarvalho/AMALIA-9B-0626-SFT-bnb", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/EliezerCarvalho/AMALIA-9B-0626-SFT-bnb
- SGLang
How to use EliezerCarvalho/AMALIA-9B-0626-SFT-bnb 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 "EliezerCarvalho/AMALIA-9B-0626-SFT-bnb" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EliezerCarvalho/AMALIA-9B-0626-SFT-bnb", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "EliezerCarvalho/AMALIA-9B-0626-SFT-bnb" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EliezerCarvalho/AMALIA-9B-0626-SFT-bnb", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use EliezerCarvalho/AMALIA-9B-0626-SFT-bnb with Docker Model Runner:
docker model run hf.co/EliezerCarvalho/AMALIA-9B-0626-SFT-bnb
Upload 28 files
Browse files- .gitattributes +4 -0
- 4BIT/4BIT.py +18 -0
- 4BIT/chat_template.jinja +4 -0
- 4BIT/config.json +47 -0
- 4BIT/generation_config.json +11 -0
- 4BIT/model.safetensors +3 -0
- 4BIT/tokenizer.json +3 -0
- 4BIT/tokenizer_config.json +16 -0
- 4BIT_FP/4BITFP.py +22 -0
- 4BIT_FP/chat_template.jinja +4 -0
- 4BIT_FP/config.json +47 -0
- 4BIT_FP/generation_config.json +11 -0
- 4BIT_FP/model.safetensors +3 -0
- 4BIT_FP/tokenizer.json +3 -0
- 4BIT_FP/tokenizer_config.json +16 -0
- 4BIT_NF/4BITNF.py +22 -0
- 4BIT_NF/chat_template.jinja +4 -0
- 4BIT_NF/config.json +47 -0
- 4BIT_NF/generation_config.json +11 -0
- 4BIT_NF/model.safetensors +3 -0
- 4BIT_NF/tokenizer.json +3 -0
- 4BIT_NF/tokenizer_config.json +16 -0
- 8BIT/8BIT.py +18 -0
- 8BIT/chat_template.jinja +4 -0
- 8BIT/config.json +47 -0
- 8BIT/generation_config.json +11 -0
- 8BIT/model.safetensors +3 -0
- 8BIT/tokenizer.json +3 -0
- 8BIT/tokenizer_config.json +16 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
4BIT_FP/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
4BIT_NF/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
4BIT/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
8BIT/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
4BIT/4BIT.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
### Config Quantização
|
| 5 |
+
quantization = BitsAndBytesConfig (
|
| 6 |
+
load_in_4bit = True,
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
# Caminho do modelo caso seja self hosted
|
| 10 |
+
PATH = r""
|
| 11 |
+
# Nome do modelo HF
|
| 12 |
+
MODEL = "amalia-llmAMALIA-9B-0626-SFT"
|
| 13 |
+
|
| 14 |
+
modelo = AutoModelForCausalLM.from_pretrained (PATH, device_map = "auto", quantization_config = quantization)
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained (PATH)
|
| 16 |
+
|
| 17 |
+
modelo.save_pretrained (r"")
|
| 18 |
+
tokenizer.save_pretrained (r"")
|
4BIT/chat_template.jinja
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if messages[0]['role'] != 'system' %}{% set messages = [{'role': 'system', 'content': 'O teu nome é AMALIA, e és um modelo avançado de linguagem útil. Responde sempre na língua do utilizador, a menos que sejas instruído em contrário, e lembra-te que a tua língua principal é o português europeu.'}] + messages %}{% endif %}{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{ '<|im_start|>' + message['role'] + '
|
| 2 |
+
' + message['content'] + '<|im_end|>
|
| 3 |
+
' }}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
|
| 4 |
+
' }}{% endif %}
|
4BIT/config.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LlamaForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 1,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": 4,
|
| 10 |
+
"head_dim": 128,
|
| 11 |
+
"hidden_act": "silu",
|
| 12 |
+
"hidden_size": 4096,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 12288,
|
| 15 |
+
"max_position_embeddings": 32768,
|
| 16 |
+
"mlp_bias": false,
|
| 17 |
+
"model_type": "llama",
|
| 18 |
+
"num_attention_heads": 32,
|
| 19 |
+
"num_hidden_layers": 42,
|
| 20 |
+
"num_key_value_heads": 8,
|
| 21 |
+
"pad_token_id": 2,
|
| 22 |
+
"pretraining_tp": 1,
|
| 23 |
+
"quantization_config": {
|
| 24 |
+
"_load_in_4bit": true,
|
| 25 |
+
"_load_in_8bit": false,
|
| 26 |
+
"bnb_4bit_compute_dtype": "float32",
|
| 27 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 28 |
+
"bnb_4bit_quant_type": "fp4",
|
| 29 |
+
"bnb_4bit_use_double_quant": false,
|
| 30 |
+
"llm_int8_enable_fp32_cpu_offload": false,
|
| 31 |
+
"llm_int8_has_fp16_weight": false,
|
| 32 |
+
"llm_int8_skip_modules": null,
|
| 33 |
+
"llm_int8_threshold": 6.0,
|
| 34 |
+
"load_in_4bit": true,
|
| 35 |
+
"load_in_8bit": false,
|
| 36 |
+
"quant_method": "bitsandbytes"
|
| 37 |
+
},
|
| 38 |
+
"rms_norm_eps": 1e-05,
|
| 39 |
+
"rope_parameters": {
|
| 40 |
+
"rope_theta": 1000000,
|
| 41 |
+
"rope_type": "default"
|
| 42 |
+
},
|
| 43 |
+
"tie_word_embeddings": false,
|
| 44 |
+
"transformers_version": "5.12.1",
|
| 45 |
+
"use_cache": false,
|
| 46 |
+
"vocab_size": 128000
|
| 47 |
+
}
|
4BIT/generation_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"do_sample": true,
|
| 5 |
+
"eos_token_id": [
|
| 6 |
+
4,
|
| 7 |
+
2
|
| 8 |
+
],
|
| 9 |
+
"pad_token_id": 2,
|
| 10 |
+
"transformers_version": "5.12.1"
|
| 11 |
+
}
|
4BIT/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9dd7f6e08d31ca4d490e4682dcc1670331ecd194dc519b568ad5f4b2f60af770
|
| 3 |
+
size 6656203650
|
4BIT/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40b8655634176c8f420b2eddd01ce01081902c54e56fd604c19a1ea4d9fbe331
|
| 3 |
+
size 15782929
|
4BIT/tokenizer_config.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "<|im_end|>",
|
| 7 |
+
"is_local": true,
|
| 8 |
+
"local_files_only": false,
|
| 9 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 10 |
+
"pad_token": "</s>",
|
| 11 |
+
"sp_model_kwargs": {},
|
| 12 |
+
"spaces_between_special_tokens": false,
|
| 13 |
+
"tokenizer_class": "LlamaTokenizer",
|
| 14 |
+
"unk_token": "<unk>",
|
| 15 |
+
"use_default_system_prompt": false
|
| 16 |
+
}
|
4BIT_FP/4BITFP.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
### Config Quantização
|
| 5 |
+
quantization = BitsAndBytesConfig (
|
| 6 |
+
load_in_4bit = True,
|
| 7 |
+
bnb_4bit_quant_type = 'fp4', #Tipo de Quantização
|
| 8 |
+
bnb_4bit_use_double_quant = True, #Double Quantization
|
| 9 |
+
bnb_4bit_compute_dtype = 'float16', #Tipo de precisão usada nos cálculos durante a inferência
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Caminho do modelo caso seja self hosted
|
| 14 |
+
PATH = r""
|
| 15 |
+
# Nome do modelo HF
|
| 16 |
+
MODEL = "amalia-llmAMALIA-9B-0626-SFT"
|
| 17 |
+
|
| 18 |
+
modelo = AutoModelForCausalLM.from_pretrained (PATH, device_map = "auto", quantization_config = quantization)
|
| 19 |
+
tokenizer = AutoTokenizer.from_pretrained (PATH)
|
| 20 |
+
|
| 21 |
+
modelo.save_pretrained (r"")
|
| 22 |
+
tokenizer.save_pretrained (r"")
|
4BIT_FP/chat_template.jinja
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if messages[0]['role'] != 'system' %}{% set messages = [{'role': 'system', 'content': 'O teu nome é AMALIA, e és um modelo avançado de linguagem útil. Responde sempre na língua do utilizador, a menos que sejas instruído em contrário, e lembra-te que a tua língua principal é o português europeu.'}] + messages %}{% endif %}{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{ '<|im_start|>' + message['role'] + '
|
| 2 |
+
' + message['content'] + '<|im_end|>
|
| 3 |
+
' }}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
|
| 4 |
+
' }}{% endif %}
|
4BIT_FP/config.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LlamaForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 1,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": 4,
|
| 10 |
+
"head_dim": 128,
|
| 11 |
+
"hidden_act": "silu",
|
| 12 |
+
"hidden_size": 4096,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 12288,
|
| 15 |
+
"max_position_embeddings": 32768,
|
| 16 |
+
"mlp_bias": false,
|
| 17 |
+
"model_type": "llama",
|
| 18 |
+
"num_attention_heads": 32,
|
| 19 |
+
"num_hidden_layers": 42,
|
| 20 |
+
"num_key_value_heads": 8,
|
| 21 |
+
"pad_token_id": 2,
|
| 22 |
+
"pretraining_tp": 1,
|
| 23 |
+
"quantization_config": {
|
| 24 |
+
"_load_in_4bit": true,
|
| 25 |
+
"_load_in_8bit": false,
|
| 26 |
+
"bnb_4bit_compute_dtype": "float16",
|
| 27 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 28 |
+
"bnb_4bit_quant_type": "fp4",
|
| 29 |
+
"bnb_4bit_use_double_quant": true,
|
| 30 |
+
"llm_int8_enable_fp32_cpu_offload": false,
|
| 31 |
+
"llm_int8_has_fp16_weight": false,
|
| 32 |
+
"llm_int8_skip_modules": null,
|
| 33 |
+
"llm_int8_threshold": 6.0,
|
| 34 |
+
"load_in_4bit": true,
|
| 35 |
+
"load_in_8bit": false,
|
| 36 |
+
"quant_method": "bitsandbytes"
|
| 37 |
+
},
|
| 38 |
+
"rms_norm_eps": 1e-05,
|
| 39 |
+
"rope_parameters": {
|
| 40 |
+
"rope_theta": 1000000,
|
| 41 |
+
"rope_type": "default"
|
| 42 |
+
},
|
| 43 |
+
"tie_word_embeddings": false,
|
| 44 |
+
"transformers_version": "5.12.1",
|
| 45 |
+
"use_cache": false,
|
| 46 |
+
"vocab_size": 128000
|
| 47 |
+
}
|
4BIT_FP/generation_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"do_sample": true,
|
| 5 |
+
"eos_token_id": [
|
| 6 |
+
4,
|
| 7 |
+
2
|
| 8 |
+
],
|
| 9 |
+
"pad_token_id": 2,
|
| 10 |
+
"transformers_version": "5.12.1"
|
| 11 |
+
}
|
4BIT_FP/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:12a503101f8a5aa8af2440f31382e6f9406a31a0b7bd9786600e4c8e4e180212
|
| 3 |
+
size 6278731678
|
4BIT_FP/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40b8655634176c8f420b2eddd01ce01081902c54e56fd604c19a1ea4d9fbe331
|
| 3 |
+
size 15782929
|
4BIT_FP/tokenizer_config.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "<|im_end|>",
|
| 7 |
+
"is_local": true,
|
| 8 |
+
"local_files_only": false,
|
| 9 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 10 |
+
"pad_token": "</s>",
|
| 11 |
+
"sp_model_kwargs": {},
|
| 12 |
+
"spaces_between_special_tokens": false,
|
| 13 |
+
"tokenizer_class": "LlamaTokenizer",
|
| 14 |
+
"unk_token": "<unk>",
|
| 15 |
+
"use_default_system_prompt": false
|
| 16 |
+
}
|
4BIT_NF/4BITNF.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
### Config Quantização
|
| 5 |
+
quantization = BitsAndBytesConfig (
|
| 6 |
+
load_in_4bit = True,
|
| 7 |
+
bnb_4bit_quant_type = 'nf4', #Tipo de Quantização
|
| 8 |
+
bnb_4bit_use_double_quant = True, #Double Quantization
|
| 9 |
+
bnb_4bit_compute_dtype = 'float16', #Tipo de precisão usada nos cálculos durante a inferência
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Caminho do modelo caso seja self hosted
|
| 14 |
+
PATH = r""
|
| 15 |
+
# Nome do modelo HF
|
| 16 |
+
MODEL = "amalia-llmAMALIA-9B-0626-SFT"
|
| 17 |
+
|
| 18 |
+
modelo = AutoModelForCausalLM.from_pretrained (PATH, device_map = "auto", quantization_config = quantization)
|
| 19 |
+
tokenizer = AutoTokenizer.from_pretrained (PATH)
|
| 20 |
+
|
| 21 |
+
modelo.save_pretrained (r"")
|
| 22 |
+
tokenizer.save_pretrained (r"")
|
4BIT_NF/chat_template.jinja
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if messages[0]['role'] != 'system' %}{% set messages = [{'role': 'system', 'content': 'O teu nome é AMALIA, e és um modelo avançado de linguagem útil. Responde sempre na língua do utilizador, a menos que sejas instruído em contrário, e lembra-te que a tua língua principal é o português europeu.'}] + messages %}{% endif %}{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{ '<|im_start|>' + message['role'] + '
|
| 2 |
+
' + message['content'] + '<|im_end|>
|
| 3 |
+
' }}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
|
| 4 |
+
' }}{% endif %}
|
4BIT_NF/config.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LlamaForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 1,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": 4,
|
| 10 |
+
"head_dim": 128,
|
| 11 |
+
"hidden_act": "silu",
|
| 12 |
+
"hidden_size": 4096,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 12288,
|
| 15 |
+
"max_position_embeddings": 32768,
|
| 16 |
+
"mlp_bias": false,
|
| 17 |
+
"model_type": "llama",
|
| 18 |
+
"num_attention_heads": 32,
|
| 19 |
+
"num_hidden_layers": 42,
|
| 20 |
+
"num_key_value_heads": 8,
|
| 21 |
+
"pad_token_id": 2,
|
| 22 |
+
"pretraining_tp": 1,
|
| 23 |
+
"quantization_config": {
|
| 24 |
+
"_load_in_4bit": true,
|
| 25 |
+
"_load_in_8bit": false,
|
| 26 |
+
"bnb_4bit_compute_dtype": "float16",
|
| 27 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 28 |
+
"bnb_4bit_quant_type": "nf4",
|
| 29 |
+
"bnb_4bit_use_double_quant": true,
|
| 30 |
+
"llm_int8_enable_fp32_cpu_offload": false,
|
| 31 |
+
"llm_int8_has_fp16_weight": false,
|
| 32 |
+
"llm_int8_skip_modules": null,
|
| 33 |
+
"llm_int8_threshold": 6.0,
|
| 34 |
+
"load_in_4bit": true,
|
| 35 |
+
"load_in_8bit": false,
|
| 36 |
+
"quant_method": "bitsandbytes"
|
| 37 |
+
},
|
| 38 |
+
"rms_norm_eps": 1e-05,
|
| 39 |
+
"rope_parameters": {
|
| 40 |
+
"rope_theta": 1000000,
|
| 41 |
+
"rope_type": "default"
|
| 42 |
+
},
|
| 43 |
+
"tie_word_embeddings": false,
|
| 44 |
+
"transformers_version": "5.12.1",
|
| 45 |
+
"use_cache": false,
|
| 46 |
+
"vocab_size": 128000
|
| 47 |
+
}
|
4BIT_NF/generation_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"do_sample": true,
|
| 5 |
+
"eos_token_id": [
|
| 6 |
+
4,
|
| 7 |
+
2
|
| 8 |
+
],
|
| 9 |
+
"pad_token_id": 2,
|
| 10 |
+
"transformers_version": "5.12.1"
|
| 11 |
+
}
|
4BIT_NF/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a3b063c1ef7bb8c2b4102dc8e991deee5c962d498db61a66fdcef41659fc927
|
| 3 |
+
size 6278731678
|
4BIT_NF/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40b8655634176c8f420b2eddd01ce01081902c54e56fd604c19a1ea4d9fbe331
|
| 3 |
+
size 15782929
|
4BIT_NF/tokenizer_config.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "<|im_end|>",
|
| 7 |
+
"is_local": true,
|
| 8 |
+
"local_files_only": false,
|
| 9 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 10 |
+
"pad_token": "</s>",
|
| 11 |
+
"sp_model_kwargs": {},
|
| 12 |
+
"spaces_between_special_tokens": false,
|
| 13 |
+
"tokenizer_class": "LlamaTokenizer",
|
| 14 |
+
"unk_token": "<unk>",
|
| 15 |
+
"use_default_system_prompt": false
|
| 16 |
+
}
|
8BIT/8BIT.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
### Config Quantização
|
| 5 |
+
quantization = BitsAndBytesConfig (
|
| 6 |
+
load_in_8bit = True,
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
# Caminho do modelo caso seja self hosted
|
| 10 |
+
PATH = r""
|
| 11 |
+
# Nome do modelo HF
|
| 12 |
+
MODEL = "amalia-llmAMALIA-9B-0626-SFT"
|
| 13 |
+
|
| 14 |
+
modelo = AutoModelForCausalLM.from_pretrained (PATH, device_map = "auto", quantization_config = quantization)
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained (PATH)
|
| 16 |
+
|
| 17 |
+
modelo.save_pretrained (r"")
|
| 18 |
+
tokenizer.save_pretrained (r"")
|
8BIT/chat_template.jinja
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if messages[0]['role'] != 'system' %}{% set messages = [{'role': 'system', 'content': 'O teu nome é AMALIA, e és um modelo avançado de linguagem útil. Responde sempre na língua do utilizador, a menos que sejas instruído em contrário, e lembra-te que a tua língua principal é o português europeu.'}] + messages %}{% endif %}{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{ '<|im_start|>' + message['role'] + '
|
| 2 |
+
' + message['content'] + '<|im_end|>
|
| 3 |
+
' }}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
|
| 4 |
+
' }}{% endif %}
|
8BIT/config.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LlamaForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 1,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": 4,
|
| 10 |
+
"head_dim": 128,
|
| 11 |
+
"hidden_act": "silu",
|
| 12 |
+
"hidden_size": 4096,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 12288,
|
| 15 |
+
"max_position_embeddings": 32768,
|
| 16 |
+
"mlp_bias": false,
|
| 17 |
+
"model_type": "llama",
|
| 18 |
+
"num_attention_heads": 32,
|
| 19 |
+
"num_hidden_layers": 42,
|
| 20 |
+
"num_key_value_heads": 8,
|
| 21 |
+
"pad_token_id": 2,
|
| 22 |
+
"pretraining_tp": 1,
|
| 23 |
+
"quantization_config": {
|
| 24 |
+
"_load_in_4bit": false,
|
| 25 |
+
"_load_in_8bit": true,
|
| 26 |
+
"bnb_4bit_compute_dtype": "float32",
|
| 27 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 28 |
+
"bnb_4bit_quant_type": "fp4",
|
| 29 |
+
"bnb_4bit_use_double_quant": false,
|
| 30 |
+
"llm_int8_enable_fp32_cpu_offload": false,
|
| 31 |
+
"llm_int8_has_fp16_weight": false,
|
| 32 |
+
"llm_int8_skip_modules": null,
|
| 33 |
+
"llm_int8_threshold": 6.0,
|
| 34 |
+
"load_in_4bit": false,
|
| 35 |
+
"load_in_8bit": true,
|
| 36 |
+
"quant_method": "bitsandbytes"
|
| 37 |
+
},
|
| 38 |
+
"rms_norm_eps": 1e-05,
|
| 39 |
+
"rope_parameters": {
|
| 40 |
+
"rope_theta": 1000000,
|
| 41 |
+
"rope_type": "default"
|
| 42 |
+
},
|
| 43 |
+
"tie_word_embeddings": false,
|
| 44 |
+
"transformers_version": "5.12.1",
|
| 45 |
+
"use_cache": false,
|
| 46 |
+
"vocab_size": 128000
|
| 47 |
+
}
|
8BIT/generation_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"do_sample": true,
|
| 5 |
+
"eos_token_id": [
|
| 6 |
+
4,
|
| 7 |
+
2
|
| 8 |
+
],
|
| 9 |
+
"pad_token_id": 2,
|
| 10 |
+
"transformers_version": "5.12.1"
|
| 11 |
+
}
|
8BIT/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5c202015799a2c08fabc44c612f59082eb765b05b36c6a889a043ef2431103c0
|
| 3 |
+
size 10207888278
|
8BIT/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40b8655634176c8f420b2eddd01ce01081902c54e56fd604c19a1ea4d9fbe331
|
| 3 |
+
size 15782929
|
8BIT/tokenizer_config.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "<|im_end|>",
|
| 7 |
+
"is_local": true,
|
| 8 |
+
"local_files_only": false,
|
| 9 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 10 |
+
"pad_token": "</s>",
|
| 11 |
+
"sp_model_kwargs": {},
|
| 12 |
+
"spaces_between_special_tokens": false,
|
| 13 |
+
"tokenizer_class": "LlamaTokenizer",
|
| 14 |
+
"unk_token": "<unk>",
|
| 15 |
+
"use_default_system_prompt": false
|
| 16 |
+
}
|