Views
No views yet
python examples/scripts/sft.py --model_name TinyLlama/TinyLlama-1.1B-Chat-v1.0 --dataset_name jtatman/python-code-dataset-500k --load_in_4bit --dataset_text_field text --per_device_train_batch_size 2 --per_device_eval_batch_size 8 --gradient_accumulation_steps 1 --learning_rate 2e-4 --optim adamw_torch --save_steps 2000 --logging_steps 500 --warmup_ratio 0 --use_peft --lora_r 64 --lora_alpha 16 --lora_dropout 0.1 --report_to wandb --num_train_epochs 1 --output_dir TinyLlama-1.1B-Chat-v1.0-PCD250k_v0.11import torch
2from transformers import pipeline
3
4pipe = pipeline("text-generation", model="SSK-DNB/TinyLlama-1.1B-Chat-v1.0-PCD250k_v0.1", torch_dtype=torch.bfloat16, device_map="auto")
5
6text = '''Create a program that determines whether a given year is a leap year or not.
7The input is an integer Y (1000 ≤ Y ≤ 2999) representing a year, provided in a single line.
8Output "YES" if the given year is a leap year, otherwise output "NO" in a single line.
9A leap year is determined according to the following rules:
10Rule 1: A year divisible by 4 is a leap year.
11Rule 2: A year divisible by 100 is not a leap year.
12Rule 3: A year divisible by 400 is a leap year.
13Rule 4: If none of the above rules (Rule 1-3) apply, the year is not a leap year.
14If a year satisfies multiple rules, the rule with the higher number takes precedence.
15'''
16texts = f"Translate the following problem statement into Python code. :\n{text}"
17messages = [
18 {"role": "system","content": "You are a chatbot who can help code!",},
19 {"role": "user", "content": f"{texts}"},
20]
21prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
22outputs = pipe(
23 prompt,
24 max_new_tokens=512,
25 do_sample=True,
26 temperature=0.1,
27 repetition_penalty=1.0,
28 top_k=50,
29 top_p=1.0,
30 min_p=0
31 )
32print(outputs[0]["generated_text"])1from llama_cpp import Llama
2
3llm = Llama(model_path="TinyLlama-1.1B-Chat-v1.0-PCD250k_v0.1_Q4_K_M.gguf", verbose=False,n_ctx=2000,n_gpu_layers=-1)
4
5system_message = "You are a chatbot who can help code!"
6text = '''Create a program that determines whether a given year is a leap year or not.
7The input is an integer Y (1000 ≤ Y ≤ 2999) representing a year, provided in a single line.
8Output "YES" if the given year is a leap year, otherwise output "NO" in a single line.
9A leap year is determined according to the following rules:
10Rule 1: A year divisible by 4 is a leap year.
11Rule 2: A year divisible by 100 is not a leap year.
12Rule 3: A year divisible by 400 is a leap year.
13Rule 4: If none of the above rules (Rule 1-3) apply, the year is not a leap year.
14If a year satisfies multiple rules, the rule with the higher number takes precedence.
15'''
16texts = f"Translate the following problem statement into Python code. :\n{text}"
17prompt = f"<|system|>\n{system_message}</s>\n<|user|>\n{texts}</s>\n<|assistant|>\n"
18output = llm(
19 prompt,
20 stop=["</s>"],
21 max_tokens=512,
22 echo=True,
23 top_k=50,
24 top_p=1.0,
25 temperature=0.1,
26 min_p=0,
27 repeat_penalty=1.0,
28 typical_p=1.0
29 )
30print(output['choices'][0]["text"])