Commit
·
9c317f9
1
Parent(s):
4e35d20
Init comit to test zamba2 7b build scripts
Browse files- app.py +44 -0
- build_script.sh +9 -0
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
+
import torch
|
| 5 |
+
from huggingface_hub import login
|
| 6 |
+
|
| 7 |
+
login(token=os.getenv('HF_TOKEN'))
|
| 8 |
+
|
| 9 |
+
# Load the tokenizer and model
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained("Zyphra/Zamba2-7B")
|
| 11 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 12 |
+
"Zyphra/Zamba2-7B",
|
| 13 |
+
device_map="auto", # Automatically handles device placement
|
| 14 |
+
torch_dtype=torch.bfloat16
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
def generate_response(input_text):
|
| 18 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to(model.device)
|
| 19 |
+
outputs = model.generate(
|
| 20 |
+
**input_ids,
|
| 21 |
+
max_new_tokens=500,
|
| 22 |
+
do_sample=True,
|
| 23 |
+
temperature=0.7,
|
| 24 |
+
top_k=50,
|
| 25 |
+
top_p=0.9,
|
| 26 |
+
repetition_penalty=1.2,
|
| 27 |
+
num_beams=5,
|
| 28 |
+
length_penalty=1.0,
|
| 29 |
+
num_return_sequences=1
|
| 30 |
+
)
|
| 31 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 32 |
+
return response
|
| 33 |
+
|
| 34 |
+
# Create the Gradio interface
|
| 35 |
+
demo = gr.Interface(
|
| 36 |
+
fn=generate_response,
|
| 37 |
+
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter your question here..."),
|
| 38 |
+
outputs="text",
|
| 39 |
+
title="Zamba2-7B Model",
|
| 40 |
+
description="Ask Zamba2 7B a question."
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
demo.launch()
|
build_script.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
git clone https://github.com/Zyphra/transformers_zamba2.git
|
| 4 |
+
cd transformers_zamba2/
|
| 5 |
+
pip install packaging
|
| 6 |
+
pip install wheel
|
| 7 |
+
pip install torch
|
| 8 |
+
pip install -e .
|
| 9 |
+
pip install accelerate
|