Instructions to use comradepenguin1917/backward-llama2-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use comradepenguin1917/backward-llama2-lora with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("NousResearch/Llama-2-7b-chat-hf") model = PeftModel.from_pretrained(base_model, "comradepenguin1917/backward-llama2-lora") - Transformers
How to use comradepenguin1917/backward-llama2-lora with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="comradepenguin1917/backward-llama2-lora")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("comradepenguin1917/backward-llama2-lora", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use comradepenguin1917/backward-llama2-lora with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "comradepenguin1917/backward-llama2-lora" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "comradepenguin1917/backward-llama2-lora", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/comradepenguin1917/backward-llama2-lora
- SGLang
How to use comradepenguin1917/backward-llama2-lora with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "comradepenguin1917/backward-llama2-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "comradepenguin1917/backward-llama2-lora", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "comradepenguin1917/backward-llama2-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "comradepenguin1917/backward-llama2-lora", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use comradepenguin1917/backward-llama2-lora with Docker Model Runner:
docker model run hf.co/comradepenguin1917/backward-llama2-lora
Model Card for Model ID
---
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))
Model details
- Base model:
NousResearch/Llama-2-7b-chat-hf(used as accessible substitute for gatedmeta-llama/Llama-2-7b-chat-hf). - Fine-tuned task: backward model p(x|y) β predict instruction given output.
- Training dataset:
timdettmers/openassistant-guanaco(openassistant-guanaco).
LoRA hyperparameters (training)
- r: 8
- alpha: 16
- dropout: 0.05
- task_type: CAUSAL_LM
Files included
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 file
How to reproduce
Run 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
License
This example uses mit as a placeholder. Replace with the appropriate license.
Contact
Please contact the author for questions about reproduction or use.
Framework versions
- PEFT 0.18.0
- Downloads last month
- 9
Model tree for comradepenguin1917/backward-llama2-lora
Base model
NousResearch/Llama-2-7b-chat-hf