Downloads · 30 days
9
43% of all-time downloads
comradepenguin1917/backward-llama2-lora
backward-llama2-lora is a text generation model from comradepenguin1917. Use it when you need the model to write or continue text. It is set up for peft.
python from transformers import AutoTokenizer, AutoModelForCausalLM from peft import PeftModel import torch
Downloads · 30 days
9
43% of all-time downloads
All-time downloads
21
Public
Repo size
101 MB
Likes
0
Public
Click a slice to open those files.
.pt67.3 MB · 57%
From the Hugging Face model README
---
language: en
license: mit
base_model: NousResearch/Llama-2-7b-chat-hf
library_name: peft
pipeline_tag: text-generation
tags:
- lora
- peft
- causal-lm
---
# Backward model p(x|y) — LoRA adapter
This repository contains a LoRA adapter trained to predict the original instruction (x) given an output/response (y). The model was finetuned on the `timdettmers/openassistant-guanaco` dataset. The adapter is intended to be loaded on top of the `NousResearch/Llama-2-7b-chat-hf` base model.
## Quick usage
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
base = "NousResearch/Llama-2-7b-chat-hf"
adapter_repo = "." # local folder or hf repo id
tokenizer = AutoTokenizer.from_pretrained(base, use_fast=False)
model = AutoModelForCausalLM.from_pretrained(base, device_map="auto", trust_remote_code=True)
model = PeftModel.from_pretrained(model, adapter_repo, device_map="auto")
prompt = "### Output:\nLeaves fall and wind sings.\n\n### Instruction:\n"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=128)
print(tokenizer.decode(out[0], skip_special_tokens=True))
NousResearch/Llama-2-7b-chat-hf (used as accessible substitute for gated meta-llama/Llama-2-7b-chat-hf).timdettmers/openassistant-guanaco (openassistant-guanaco).adapter_config.json — PEFT adapter configadapter_model.safetensors — LoRA adapter weightscheckpoint-250/, checkpoint-500/ — intermediate adapter checkpoints and trainer statetraining_args.bin — HF Trainer training argsREADME.md — this fileRun train_backward.py in this repository. Example training command used for experiments (adjust per GPU resources):
python train_backward.py \
--model_name NousResearch/Llama-2-7b-chat-hf \
--load_in_4bit \
--num_train_epochs 2 \
--per_device_train_batch_size 1 \
--gradient_accumulation_steps 8 \
--max_train_samples 5000 \
--output_dir ./backward-finetuned
This example uses mit as a placeholder. Replace with the appropriate license.
Please contact the author for questions about reproduction or use.