Downloads · 30 days
0
SwastikM/Meta-Llama3-8B-Chat-Instruct-LoRA
Meta-Llama3-8B-Chat-Instruct-LoRA is a text generation model from SwastikM. Use it when you need the model to write or continue text. It is set up for transformers.
Downloads · 30 days
0
Access
Public
Updated Jul 23, 2024
Repo size
68.2 MB
Likes
0
Public
Click a slice to open those files.
.safetensors13.6 MB · 100%
From the Hugging Face model README
Function-Calling Agent
Parameter Efficient Finetuning (PEFT) a 4bit quantized Meta-Llama-3-8B-Instruct on Salesforce/xlam-function-calling-60k dataset.
Addressing the efficay of Quantization and PEFT. Implemented as a personal Project.
!pip install transformers accelerate bitsandbytes>0.37.0
!pip install peft
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer,AutoModelForCausalLM
from peft import PeftModel, PeftConfig, get_peft_model
import torch
base_model = AutoModelForCausalLM.from_pretrained("SwastikM/Meta-Llama-3-8B-Instruct_bitsandbytes_4bit",device_map="auto")
model = PeftModel.from_pretrained(base_model, "SwastikM/Meta-Llama3-8B-Chat-Adapter")
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct")
model = model.to("cuda")
model.eval()
x1 = {"role": "system", "content": """You are a APIGen Function Calling Tool. You will br provided with a user query and associated tools for answering the query.
query (string): The query or problem statement.
tools (array): An array of available tools that can be used to solve the query.
Each tool is represented as an object with the following properties:
name (string): The name of the tool.
description (string): A brief description of what the tool does.
parameters (object): An object representing the parameters required by the tool.
Each parameter is represented as a key-value pair, where the key is the parameter name and the value is an object with the following properties:
type (string): The data type of the parameter (e.g., "int", "float", "list").
description (string): A brief description of the parameter.
required (boolean): Indicates whether the parameter is required or optional.
You will provide the Answer array.
Answers array provides the specific tool and arguments used to generate each answer."""}
x2 = {"role": "user", "content": None}
x3 = {"role": "assistant", "content": None}
user_template = 'Query: {Q} Tools: {T}'
response_template = '{A}'
Q = "Where can I find live giveaways for beta access and games?"
T = """[{"name": "live_giveaways_by_type", "description": "Retrieve live giveaways from the GamerPower API based on the specified type.", "parameters": {"type": {"description": "The type of giveaways to retrieve (e.g., game, loot, beta).", "type": "str", "default": "game"}}}]"""
x2['content'] = f'{user_template.format(Q=Q,T=T)}'
prompts = [x1,x2]
input_ids = tokenizer.apply_chat_template(
prompts,
add_generation_prompt=True,
return_tensors="pt"
).to(model.device)
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>")
]
outputs = model.generate(
input_ids,
max_new_tokens=256,
eos_token_id=terminators
)
response = outputs[0][input_ids.shape[-1]:]
print(tokenizer.decode(response, skip_special_tokens=True))
The table shows comparison VRAM requirements for loading and training of FP16 Base Model and 4bit bnb quantized model with PEFT. The value for base model referenced from Model Memory Calculator from HuggingFace
| Model | Total Size | Training Using Adam |
|---|---|---|
| Base Model | 28.21 GB | 56.42 GB |
| 4bitQuantized+PEFT | 5.21 GB | 13 GB |
Dataset: Salesforce/xlam-function-calling-60k dataset
Trained on instruction column of 20,00 randomly shuffled data.
HuggingFace Accelerate with Training Loop.
LoraConfig
Swastik Maiti