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: apache-2.0
|
| 12 |
+
language:
|
| 13 |
+
- code
|
| 14 |
+
datasets:
|
| 15 |
+
- iamtarun/python_code_instructions_18k_alpaca
|
| 16 |
+
pipeline_tag: text-generation
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# TinyLlaMa 1.1B 1431k 4-bit Python Coder 👩💻
|
| 21 |
+
|
| 22 |
+
**TinyLlaMa 1.1B** fine-tuned on the **python_code_instructions_18k_alpaca Code instructions dataset** by using the **Axolot** library in 4-bit with [PEFT](https://github.com/huggingface/peft) library.
|
| 23 |
+
|
| 24 |
+
## Pretrained description
|
| 25 |
+
|
| 26 |
+
[TinyLlama-1.1B](https://huggingface.co/TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T)
|
| 27 |
+
|
| 28 |
+
The [TinyLlama project](https://github.com/jzhang38/TinyLlama) aims to pretrain a 1.1B Llama model on 3 trillion tokens. With some proper optimization, they can achieve this within a span of "just" 90 days using 16 A100-40G GPUs 🚀🚀.
|
| 29 |
+
|
| 30 |
+
They adopted exactly the same architecture and tokenizer as Llama 2. This means TinyLlama can be plugged and played in many open-source projects built upon Llama. Besides, TinyLlama is compact with only 1.1B parameters. This compactness allows it to cater to a multitude of applications demanding a restricted computation and memory footprint.
|
| 31 |
+
|
| 32 |
+
## Training data
|
| 33 |
+
|
| 34 |
+
[python_code_instructions_18k_alpaca](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca)
|
| 35 |
+
|
| 36 |
+
The dataset contains problem descriptions and code in python language. This dataset is taken from sahil2801/code_instructions_120k, which adds a prompt column in alpaca style.
|
| 37 |
+
|
| 38 |
+
### Training hyperparameters
|
| 39 |
+
|
| 40 |
+
The following `axolot` configuration was used during training:
|
| 41 |
+
|
| 42 |
+
- load_in_8bit: false
|
| 43 |
+
- load_in_4bit: true
|
| 44 |
+
- strict: false
|
| 45 |
+
|
| 46 |
+
- datasets:
|
| 47 |
+
- path: iamtarun/python_code_instructions_18k_alpaca
|
| 48 |
+
type: alpaca
|
| 49 |
+
- dataset_prepared_path:
|
| 50 |
+
- val_set_size: 0.05
|
| 51 |
+
- output_dir: ./qlora-out
|
| 52 |
+
|
| 53 |
+
- adapter: qlora
|
| 54 |
+
- sequence_len: 1096
|
| 55 |
+
- sample_packing: true
|
| 56 |
+
- pad_to_sequence_len: true
|
| 57 |
+
- lora_r: 32
|
| 58 |
+
- lora_alpha: 16
|
| 59 |
+
- lora_dropout: 0.05
|
| 60 |
+
- lora_target_modules:
|
| 61 |
+
- lora_target_linear: true
|
| 62 |
+
- lora_fan_in_fan_out:
|
| 63 |
+
- gradient_accumulation_steps: 1
|
| 64 |
+
- micro_batch_size: 1
|
| 65 |
+
- num_epochs: 2
|
| 66 |
+
- max_steps:
|
| 67 |
+
- optimizer: paged_adamw_32bit
|
| 68 |
+
- lr_scheduler: cosine
|
| 69 |
+
- learning_rate: 0.0002
|
| 70 |
+
- train_on_inputs: false
|
| 71 |
+
- group_by_length: false
|
| 72 |
+
- bf16: false
|
| 73 |
+
- fp16: true
|
| 74 |
+
- tf32: false
|
| 75 |
+
- gradient_checkpointing: true
|
| 76 |
+
- logging_steps: 10
|
| 77 |
+
- flash_attention: false
|
| 78 |
+
- warmup_steps: 10
|
| 79 |
+
- weight_decay: 0.0
|
| 80 |
+
|
| 81 |
+
### Framework versions
|
| 82 |
+
- torch=="2.1.2"
|
| 83 |
+
- flash-attn=="2.5.0"
|
| 84 |
+
- deepspeed=="0.13.1"
|
| 85 |
+
- axolotl=="0.4.0"
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
### Example of usage
|
| 89 |
+
|
| 90 |
+
```py
|
| 91 |
+
import torch
|
| 92 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 93 |
+
|
| 94 |
+
model_id = "edumunozsala/TinyLlama-1431k-python-coder"
|
| 95 |
+
|
| 96 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 97 |
+
|
| 98 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True, torch_dtype=torch.float16,
|
| 99 |
+
device_map="auto")
|
| 100 |
+
|
| 101 |
+
instruction="Write a Python function to display the first and last elements of a list."
|
| 102 |
+
input=""
|
| 103 |
+
|
| 104 |
+
prompt = f"""### Instruction:
|
| 105 |
+
Use the Task below and the Input given to write the Response, which is a programming code that can solve the Task.
|
| 106 |
+
|
| 107 |
+
### Task:
|
| 108 |
+
{instruction}
|
| 109 |
+
|
| 110 |
+
### Input:
|
| 111 |
+
{input}
|
| 112 |
+
|
| 113 |
+
### Response:
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
|
| 117 |
+
# with torch.inference_mode():
|
| 118 |
+
outputs = model.generate(input_ids=input_ids, max_new_tokens=100, do_sample=True, top_p=0.9,temperature=0.3)
|
| 119 |
+
|
| 120 |
+
print(f"Prompt:\n{prompt}\n")
|
| 121 |
+
print(f"Generated instruction:\n{tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]}")
|
| 122 |
+
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
### Citation
|
| 126 |
+
|
| 127 |
+
```
|
| 128 |
+
@misc {edumunozsala_2023,
|
| 129 |
+
author = { {Eduardo Muñoz} },
|
| 130 |
+
title = { TinyLlama-1431k-python-coder },
|
| 131 |
+
year = 2024,
|
| 132 |
+
url = { https://huggingface.co/edumunozsala/TinyLlama-1431k-python-coder },
|
| 133 |
+
publisher = { Hugging Face }
|
| 134 |
+
}
|
| 135 |
+
```
|