dinhnhat241103 commited on
Commit
a2c4a0a
·
verified ·
1 Parent(s): d9ab1d4

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ 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
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - vi
5
+ base_model: [microsoft/phi-4-mini-instruct]
6
+ tags:
7
+ - finetuned
8
+ - lora
9
+ - quantized
10
+ - vietnamese
11
+ - vmlu
12
+ datasets:
13
+ - 5CD-AI/Vietnamese-nampdn-ai-tiny-webtext-gg-translated
14
+ metrics:
15
+ - VMLU
16
+ ---
17
+
18
+ # Phi-4-mini-Vietnamese-Instruct
19
+
20
+ ## Model Description
21
+
22
+ - **Base Model:** `microsoft/phi-4-mini-instruct`
23
+ - **Finetuning Technique:** Low-Rank Adaptation (LoRA)
24
+ - **Quantization:** 4-bit NF4 using `bitsandbytes`
25
+ - **Purpose:** To create a powerful yet lightweight model capable of understanding and generating high-quality Vietnamese text.
26
+
27
+ The LoRA weights were merged into the base model, and the resulting model was quantized to optimize for performance and reduce memory footprint, making it suitable for deployment on consumer-grade hardware.
28
+
29
+ ## How to Use
30
+
31
+ As the LoRA weights have been merged, you can use this model directly with the `transformers` library without needing the `peft` library for inference.
32
+
33
+ ```python
34
+ import torch
35
+ from transformers import AutoModelForCausalLM, AutoTokenizer
36
+
37
+ model_id = "your-username/your-repo-name"
38
+
39
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
40
+ model = AutoModelForCausalLM.from_pretrained(
41
+ model_id,
42
+ device_map="auto",
43
+ torch_dtype=torch.bfloat16, # Use bfloat16 for faster inference
44
+ trust_remote_code=True
45
+ )
46
+
47
+ # Create a prompt using the chat template
48
+ # This is the recommended way for instruction-tuned models
49
+ messages = [
50
+ {"role": "user", "content": "Hãy viết một đoạn văn ngắn giải thích về Lượng tử hóa trong AI."},
51
+ ]
52
+
53
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
54
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
55
+
56
+ # Generate text
57
+ outputs = model.generate(
58
+ **inputs,
59
+ max_new_tokens=512,
60
+ eos_token_id=tokenizer.eos_token_id,
61
+ do_sample=True,
62
+ temperature=0.7,
63
+ top_p=0.9,
64
+ )
65
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
66
+
67
+ # Print the generated text, extracting only the assistant's response
68
+ print(response.split("<|assistant|>")[1].strip())
69
+
70
+ ```
71
+ ## Finetuning Details
72
+
73
+ The model was fine-tuned on the [5CD-AI/Vietnamese-nampdn-ai-tiny-webtext-gg-translated](https://huggingface.co/datasets/5CD-AI/Vietnamese-nampdn-ai-tiny-webtext-gg-translated) dataset.
74
+
75
+ - LoRA Rank: 16
76
+ - LoRA Alpha: 32
77
+ - Training Epochs: 1
78
+ - Number of Sample: 500000
79
+
80
+ ## Evaluation results
81
+
82
+ The model's performance was evaluated on the Vietnamese Machine Learning Understanding (VMLU) benchmark.
83
+
84
+
85
+
86
+ | Model | Social Science | Stem | Humanities | Others | Avg |
87
+ | -------------------- | :------------: | :------------: | :------------: | :------------: | :------------: |
88
+ | Phi-4 mini Vietnamese | 40.85 | 48 | 42.06 | 43.31 | 42.84 |
added_tokens.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "<|/tool_call|>": 200026,
3
+ "<|/tool|>": 200024,
4
+ "<|assistant|>": 200019,
5
+ "<|end|>": 200020,
6
+ "<|system|>": 200022,
7
+ "<|tag|>": 200028,
8
+ "<|tool_call|>": 200025,
9
+ "<|tool_response|>": 200027,
10
+ "<|tool|>": 200023,
11
+ "<|user|>": 200021
12
+ }
config.json ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Phi3ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "microsoft/Phi-4-mini-instruct--configuration_phi3.Phi3Config",
9
+ "AutoModelForCausalLM": "microsoft/Phi-4-mini-instruct--modeling_phi3.Phi3ForCausalLM",
10
+ "AutoTokenizer": "microsoft/Phi-4-mini-instruct--Xenova/gpt-4o"
11
+ },
12
+ "bos_token_id": 199999,
13
+ "embd_pdrop": 0.0,
14
+ "eos_token_id": 199999,
15
+ "full_attn_mod": 1,
16
+ "hidden_act": "silu",
17
+ "hidden_size": 3072,
18
+ "initializer_range": 0.02,
19
+ "intermediate_size": 8192,
20
+ "interpolate_factor": 1,
21
+ "lm_head_bias": false,
22
+ "max_position_embeddings": 131072,
23
+ "mlp_bias": false,
24
+ "model_type": "phi3",
25
+ "num_attention_heads": 24,
26
+ "num_hidden_layers": 32,
27
+ "num_key_value_heads": 8,
28
+ "original_max_position_embeddings": 4096,
29
+ "pad_token_id": 199999,
30
+ "partial_rotary_factor": 0.75,
31
+ "quantization_config": {
32
+ "_load_in_4bit": true,
33
+ "_load_in_8bit": false,
34
+ "bnb_4bit_compute_dtype": "bfloat16",
35
+ "bnb_4bit_quant_storage": "uint8",
36
+ "bnb_4bit_quant_type": "nf4",
37
+ "bnb_4bit_use_double_quant": true,
38
+ "llm_int8_enable_fp32_cpu_offload": false,
39
+ "llm_int8_has_fp16_weight": false,
40
+ "llm_int8_skip_modules": null,
41
+ "llm_int8_threshold": 6.0,
42
+ "load_in_4bit": true,
43
+ "load_in_8bit": false,
44
+ "quant_method": "bitsandbytes"
45
+ },
46
+ "resid_pdrop": 0.0,
47
+ "rms_norm_eps": 1e-05,
48
+ "rope_scaling": {
49
+ "long_factor": [
50
+ 1,
51
+ 1.118320672,
52
+ 1.250641126,
53
+ 1.398617824,
54
+ 1.564103225,
55
+ 1.74916897,
56
+ 1.956131817,
57
+ 2.187582649,
58
+ 2.446418898,
59
+ 2.735880826,
60
+ 3.059592084,
61
+ 3.421605075,
62
+ 3.826451687,
63
+ 4.279200023,
64
+ 4.785517845,
65
+ 5.351743533,
66
+ 5.984965424,
67
+ 6.693110555,
68
+ 7.485043894,
69
+ 8.370679318,
70
+ 9.36110372,
71
+ 10.4687158,
72
+ 11.70738129,
73
+ 13.09260651,
74
+ 14.64173252,
75
+ 16.37415215,
76
+ 18.31155283,
77
+ 20.47818807,
78
+ 22.90118105,
79
+ 25.61086418,
80
+ 28.64115884,
81
+ 32.03,
82
+ 32.1,
83
+ 32.13,
84
+ 32.23,
85
+ 32.6,
86
+ 32.61,
87
+ 32.64,
88
+ 32.66,
89
+ 32.7,
90
+ 32.71,
91
+ 32.93,
92
+ 32.97,
93
+ 33.28,
94
+ 33.49,
95
+ 33.5,
96
+ 44.16,
97
+ 47.77
98
+ ],
99
+ "short_factor": [
100
+ 1.0,
101
+ 1.0,
102
+ 1.0,
103
+ 1.0,
104
+ 1.0,
105
+ 1.0,
106
+ 1.0,
107
+ 1.0,
108
+ 1.0,
109
+ 1.0,
110
+ 1.0,
111
+ 1.0,
112
+ 1.0,
113
+ 1.0,
114
+ 1.0,
115
+ 1.0,
116
+ 1.0,
117
+ 1.0,
118
+ 1.0,
119
+ 1.0,
120
+ 1.0,
121
+ 1.0,
122
+ 1.0,
123
+ 1.0,
124
+ 1.0,
125
+ 1.0,
126
+ 1.0,
127
+ 1.0,
128
+ 1.0,
129
+ 1.0,
130
+ 1.0,
131
+ 1.0,
132
+ 1.0,
133
+ 1.0,
134
+ 1.0,
135
+ 1.0,
136
+ 1.0,
137
+ 1.0,
138
+ 1.0,
139
+ 1.0,
140
+ 1.0,
141
+ 1.0,
142
+ 1.0,
143
+ 1.0,
144
+ 1.0,
145
+ 1.0,
146
+ 1.0,
147
+ 1.0
148
+ ],
149
+ "type": "longrope"
150
+ },
151
+ "rope_theta": 10000.0,
152
+ "sliding_window": 262144,
153
+ "tie_word_embeddings": true,
154
+ "torch_dtype": "float16",
155
+ "transformers_version": "4.51.3",
156
+ "use_cache": true,
157
+ "vocab_size": 200064
158
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 199999,
4
+ "eos_token_id": [
5
+ 200020,
6
+ 199999
7
+ ],
8
+ "pad_token_id": 199999,
9
+ "transformers_version": "4.51.3"
10
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:953386f337ec332de9a2ec01e32ad4ac256ce5bd0b320ee02ee9487e9f755346
3
+ size 2891584577
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|endoftext|>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|endoftext|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<|endoftext|>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<|endoftext|>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:382cc235b56c725945e149cc25f191da667c836655efd0857b004320e90e91ea
3
+ size 15524095
tokenizer_config.json ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": false,
5
+ "added_tokens_decoder": {
6
+ "199999": {
7
+ "content": "<|endoftext|>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "200018": {
15
+ "content": "<|endofprompt|>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "200019": {
23
+ "content": "<|assistant|>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": true,
27
+ "single_word": false,
28
+ "special": true
29
+ },
30
+ "200020": {
31
+ "content": "<|end|>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": true,
35
+ "single_word": false,
36
+ "special": true
37
+ },
38
+ "200021": {
39
+ "content": "<|user|>",
40
+ "lstrip": false,
41
+ "normalized": false,
42
+ "rstrip": true,
43
+ "single_word": false,
44
+ "special": true
45
+ },
46
+ "200022": {
47
+ "content": "<|system|>",
48
+ "lstrip": false,
49
+ "normalized": false,
50
+ "rstrip": true,
51
+ "single_word": false,
52
+ "special": true
53
+ },
54
+ "200023": {
55
+ "content": "<|tool|>",
56
+ "lstrip": false,
57
+ "normalized": false,
58
+ "rstrip": true,
59
+ "single_word": false,
60
+ "special": false
61
+ },
62
+ "200024": {
63
+ "content": "<|/tool|>",
64
+ "lstrip": false,
65
+ "normalized": false,
66
+ "rstrip": true,
67
+ "single_word": false,
68
+ "special": false
69
+ },
70
+ "200025": {
71
+ "content": "<|tool_call|>",
72
+ "lstrip": false,
73
+ "normalized": false,
74
+ "rstrip": true,
75
+ "single_word": false,
76
+ "special": false
77
+ },
78
+ "200026": {
79
+ "content": "<|/tool_call|>",
80
+ "lstrip": false,
81
+ "normalized": false,
82
+ "rstrip": true,
83
+ "single_word": false,
84
+ "special": false
85
+ },
86
+ "200027": {
87
+ "content": "<|tool_response|>",
88
+ "lstrip": false,
89
+ "normalized": false,
90
+ "rstrip": true,
91
+ "single_word": false,
92
+ "special": false
93
+ },
94
+ "200028": {
95
+ "content": "<|tag|>",
96
+ "lstrip": false,
97
+ "normalized": false,
98
+ "rstrip": true,
99
+ "single_word": false,
100
+ "special": true
101
+ }
102
+ },
103
+ "bos_token": "<|endoftext|>",
104
+ "chat_template": "{% for message in messages %}{% if message['role'] == 'system' and 'tools' in message and message['tools'] is not none %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|tool|>' + message['tools'] + '<|/tool|>' + '<|end|>' }}{% else %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|end|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>' }}{% else %}{{ eos_token }}{% endif %}",
105
+ "clean_up_tokenization_spaces": false,
106
+ "eos_token": "<|endoftext|>",
107
+ "extra_special_tokens": {},
108
+ "model_max_length": 131072,
109
+ "pad_token": "<|endoftext|>",
110
+ "tokenizer_class": "GPT2Tokenizer",
111
+ "unk_token": "<|endoftext|>"
112
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff