Instructions to use Ahrefs/flan-llama-7b-delta with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ahrefs/flan-llama-7b-delta with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Ahrefs/flan-llama-7b-delta")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Ahrefs/flan-llama-7b-delta") model = AutoModelForCausalLM.from_pretrained("Ahrefs/flan-llama-7b-delta") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Ahrefs/flan-llama-7b-delta with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Ahrefs/flan-llama-7b-delta" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ahrefs/flan-llama-7b-delta", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Ahrefs/flan-llama-7b-delta
- SGLang
How to use Ahrefs/flan-llama-7b-delta 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 "Ahrefs/flan-llama-7b-delta" \ --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": "Ahrefs/flan-llama-7b-delta", "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 "Ahrefs/flan-llama-7b-delta" \ --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": "Ahrefs/flan-llama-7b-delta", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Ahrefs/flan-llama-7b-delta with Docker Model Runner:
docker model run hf.co/Ahrefs/flan-llama-7b-delta
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Ahrefs/flan-llama-7b-delta
NOTE: This "delta model" cannot be used directly.
Users have to apply it on top of the original LLaMA weights to get actual flan-llama weights. (sample refer below)
How to Use:
device = 0 # Define your GPU device here
llama_path = '' # Define your original llama-7b load path here (huggingface checkpoint)
import transformers
from collections import OrderedDict
model_llama = transformers.AutoModelForCausalLM.from_pretrained(llama_path)
tokenizer = transformers.AutoTokenizer.from_pretrained(llama_path)
model_flan_llama = transformers.AutoModelForCausalLM.from_pretrained("Ahrefs/flan-llama-7b-delta")
model_state_dict = []
for key in model_flan_llama.state_dict().keys():
model_state_dict.append((key, model_flan_llama.state_dict()[key]+model_llama.state_dict()[key]))
model_state_dict = OrderedDict(model_state_dict)
model_flan_llama.load_state_dict(model_state_dict)
model_flan_llama = model_flan_llama.to(device)
model_flan_llama.eval()
def generate(prompt, model, device):
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
gen_output = model.generate(input_ids.to(device), max_new_tokens=512, early_stopping=True)[0]
answer_cot = tokenizer.decode(gen_output, skip_special_tokens=True)
return answer_cot
prompt = "Can Geoffrey Hinton have a conversation with George Washington? Give the rationale before answering."
print(generate(prompt, model_flan_llama, device))
output:
Can Geoffrey Hinton have a conversation with George Washington? Give the rationale before answering. Geoffrey Hinton is a living person. George Washington was not alive when Geoffrey Hinton was born. The final answer: no.
Dataset and Training:
We finetune the original llama-7b model on extracted and sampled Flan-2022 dataset. The data are filtered to be limited to maximum source sequence length of 1536, and maximum target sequence length of 512, which accounts for roughly 5.5mil samples. (The sampled and extracted unfiltered dataset to be published on huggingface datasets soon)
We finetune the original llama-7b model on 8 A100 GPUs using pytorch's FSDP, with a learning rate of 2e-5, with warm up ratio of 0.03 and cosine rate decay, and batch size of 128.
Evaluation Results
We ran EleutherAI's evaluation harness v0.3.0 using same benchmarks and parametrezation as HF Open LLM Leaderboard:
| arc_challenge (acc_norm, 25-shot) | hellaswag (acc_norm, 10-shot) | mmlu (acc, 5-shot) | truthfulqa_mc (mc2, 0-shot) |
|---|---|---|---|
| 40.2 | 64.2 | 50.0 | 31.7 |
Reference
@article{wei2021finetuned, title={Finetuned language models are zero-shot learners}, author={Wei, Jason and Bosma, Maarten and Zhao, Vincent Y and Guu, Kelvin and Yu, Adams Wei and Lester, Brian and Du, Nan and Dai, Andrew M and Le, Quoc V}, journal={arXiv preprint arXiv:2109.01652}, year={2021} }
* [LLaMA: Open and Efficient Foundation Language Models](https://arxiv.org/abs/2302.13971)
@article{touvron2023llama, title={LLaMA: Open and Efficient Foundation Language Models}, author={Touvron, Hugo and Lavril, Thibaut and Izacard, Gautier and Martinet, Xavier and Lachaux, Marie-Anne and Lacroix, Timoth{'e}e and Rozi{`e}re, Baptiste and Goyal, Naman and Hambro, Eric and Azhar, Faisal and Rodriguez, Aurelien and Joulin, Armand and Grave, Edouard and Lample, Guillaume}, journal={arXiv preprint arXiv:2302.13971}, year={2023} }
- Downloads last month
- -