dsfdfsghgf commited on
Commit
1a81cef
1 Parent(s): 863a24d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -8
app.py CHANGED
@@ -1,11 +1,33 @@
1
- from transformers import pipeline, AutoTokenizer, AutoModel
 
2
 
3
- # Authentifizierung mit deinem Token
4
- hf_token = "HF_TOKEN"
5
 
6
- # Pipeline-Beispiel
7
- pipe = pipeline("text-classification", model="Qwen/Qwen2.5-Math-RM-72B", trust_remote_code=True, token=hf_token)
 
 
 
 
 
8
 
9
- # Direktes Modell-Beispiel
10
- tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Math-RM-72B", trust_remote_code=True, token=hf_token)
11
- model = AutoModel.from_pretrained("Qwen/Qwen2.5-Math-RM-72B", trust_remote_code=True, token=hf_token)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModel, AutoTokenizer
3
 
4
+ model_name = "Qwen/Qwen2.5-Math-RM-72B"
5
+ device = "cuda" if torch.cuda.is_available() else "cpu"
6
 
7
+ # Modell und Tokenizer laden
8
+ model = AutoModel.from_pretrained(
9
+ model_name,
10
+ device_map="auto",
11
+ torch_dtype=torch.bfloat16,
12
+ trust_remote_code=True,
13
+ ).eval()
14
 
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
16
+
17
+ # Eingabe für das Gesprächsmodell erstellen
18
+ chat = [
19
+ {"role": "system", "content": "Please reason step by step, and put your final answer within \\boxed{}."},
20
+ {"role": "user", "content": "Janet’s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?"}
21
+ ]
22
+
23
+ # Vorbereitung des Eingabeformats
24
+ conversation_str = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=False)
25
+
26
+ # Tokenisierung der Eingabe
27
+ input_ids = tokenizer.encode(conversation_str, return_tensors="pt", add_special_tokens=False).to(model.device)
28
+
29
+ # Inferenz durchführen
30
+ with torch.no_grad():
31
+ outputs = model(input_ids=input_ids)
32
+
33
+ print(outputs[0]) # Anpassen je nach Ausgabeformat