Views
No views yet
1# Model Parameters
2max_seq_length = 2048
3dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
4load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
5
6# LoRA Parameters
7r = 16
8target_modules = ["gate_proj", "up_proj", "down_proj"]
9#target_modules = ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj",],
10lora_alpha = 16
11
12# Training parameters
13learning_rate = 2e-4
14weight_decay = 0.01
15#Evaluation
16evaluation_strategy="no"
17eval_steps= 50
18
19# if training in epochs
20#num_train_epochs=2
21#save_strategy="epoch"
22
23# if training in steps
24max_steps = 1500
25save_strategy="steps"
26save_steps=500
27
28logging_steps=100
29warmup_steps = 10
30warmup_ratio=0.01
31batch_size = 4
32gradient_accumulation_steps = 4
33lr_scheduler_type = "linear"
34optimizer = "adamw_8bit"
35use_gradient_checkpointing = True
36random_state = 421import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "edumunozsala/unsloth-llama-2-7B-python-coder"
5
6# Load the entire model on the GPU 0
7device_map = {"": 0}
8
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True, torch_dtype=torch.float16,
12 device_map="auto")
13
14instruction="Write a Python function to display the first and last elements of a list."
15input=""
16
17prompt = f"""### Instruction:
18Use the Task below and the Input given to write the Response, which is a programming code that can solve the Task.
19
20### Task:
21{instruction}
22
23### Input:
24{input}
25
26### Response:
27"""
28
29input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
30# with torch.inference_mode():
31outputs = model.generate(input_ids=input_ids, max_new_tokens=100, do_sample=True, top_p=0.9,temperature=0.3)
32
33print(f"Prompt:\n{prompt}\n")
34print(f"Generated instruction:\n{tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]}")
35@misc {edumunozsala_2023,
author = { {Eduardo Muñoz} },
title = { unsloth-llama-2-7B-python-coder },
year = 2024,
url = { https://huggingface.co/edumunozsala/unsloth-llama-2-7B-python-coder },
publisher = { Hugging Face }
}