File size: 2,061 Bytes
fe7aeae 08a2621 226c266 fe7aeae 08a2621 1c8ce21 08a2621 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
---
language: en
datasets:
- truthful_qa
license: apache-2.0
tags:
- qlora
- falcon
- fine-tuning
- nlp
- causal-lm
- h100
library_name: peft
base_model: tiiuae/falcon-7b-instruct
---
# Falcon-7B QLoRA Fine-Tuned on TruthfulQA
## Model Description
This model is a fine-tuned version of the `tiiuae/falcon-7b-instruct` using the QLoRA technique on the [TruthfulQA](https://huggingface.co/datasets/truthful_qa) dataset.
## Training
- **Base Model**: [tiiuae/falcon-7b-instruct](https://huggingface.co/tiiuae/falcon-7b-instruct)
- **Dataset**: [TruthfulQA](https://huggingface.co/datasets/truthful_qa)
- **Training Technique**: QLoRA
- **Hardware**: H100 GPUs
- **Epochs**: 10
- **Batch Size**: 16
- **Learning Rate**: 2e-4
### How to Use
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# Load the base model
base_model_name = "tiiuae/falcon-7b-instruct"
base_model = AutoModelForCausalLM.from_pretrained(base_model_name)
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
# Load the adapter and apply it to the base model
adapter_repo_name = "MohammadOthman/falcon-7b-qlora-truthfulqa"
model = PeftModel.from_pretrained(base_model, adapter_repo_name)
# Move model to GPU if available
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
# Function to generate text
def generate_text(prompt, max_length=100, num_return_sequences=1):
# Tokenize the input prompt
inputs = tokenizer(prompt, return_tensors="pt").to(device)
# Generate text
outputs = model.generate(
input_ids=inputs["input_ids"],
attention_mask=inputs["attention_mask"],
max_length=max_length,
num_return_sequences=num_return_sequences,
do_sample=True,
temperature=0.7
)
# Decode and print the output
for i, output in enumerate(outputs):
print(f"Generated Text {i+1}: {tokenizer.decode(output, skip_special_tokens=True)}")
# Example usage
prompt = "Once upon a time in a land far, far away"
generate_text(prompt)
``` |