Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
9 |
#model_name = "RickyDeSkywalker/TheoremLlama"
|
10 |
#model_name = "unsloth/Llama-3.2-1B-Instruct"
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
-
model_name = "internlm/internlm2-math-plus-7b"
|
|
|
13 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
14 |
#login(HF_TOKEN)
|
15 |
|
@@ -17,6 +18,10 @@ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
17 |
# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
|
18 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, torch_dtype=torch.float16).eval().to(device)
|
19 |
model = model.eval()
|
|
|
|
|
|
|
|
|
20 |
|
21 |
#generator = pipeline('text-generation', model=model_name, trust_remote_code=True, token=HF_TOKEN)
|
22 |
|
@@ -25,9 +30,13 @@ model = model.eval()
|
|
25 |
def generate_lean4_code(prompt):
|
26 |
#result = generator(prompt, max_length=1000, num_return_sequences=1)
|
27 |
#return result[0]['generated_text']
|
28 |
-
response, history = model.chat(tokenizer, prompt, history=[], meta_instruction="")
|
29 |
-
print(response, history)
|
30 |
-
return response
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Gradio Interface
|
33 |
title = "Lean 4 Code Generation with TheoremLlama"
|
|
|
9 |
#model_name = "RickyDeSkywalker/TheoremLlama"
|
10 |
#model_name = "unsloth/Llama-3.2-1B-Instruct"
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
+
#model_name = "internlm/internlm2-math-plus-7b"
|
13 |
+
model_name = "deepseek-ai/DeepSeek-Prover-V1.5-RL"
|
14 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
15 |
#login(HF_TOKEN)
|
16 |
|
|
|
18 |
# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
|
19 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, torch_dtype=torch.float16).eval().to(device)
|
20 |
model = model.eval()
|
21 |
+
terminators = [tokenizer.eos_token_id,
|
22 |
+
tokenizer.convert_tokens_to_ids("<|eot_id|>"),
|
23 |
+
tokenizer.convert_tokens_to_ids("<|reserved_special_token_26|>")]
|
24 |
+
|
25 |
|
26 |
#generator = pipeline('text-generation', model=model_name, trust_remote_code=True, token=HF_TOKEN)
|
27 |
|
|
|
30 |
def generate_lean4_code(prompt):
|
31 |
#result = generator(prompt, max_length=1000, num_return_sequences=1)
|
32 |
#return result[0]['generated_text']
|
33 |
+
#response, history = model.chat(tokenizer, prompt, history=[], meta_instruction="")
|
34 |
+
#print(response, history)
|
35 |
+
#return response
|
36 |
+
input_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(device)
|
37 |
+
results = model.generate(input_ids, max_new_tokens=1024, eos_token_id=terminators, do_sample=True, temperature=0.85, top_p=0.9)
|
38 |
+
result_str = tokenizer.decode(results[0], skip_special_tokens=True)
|
39 |
+
return result_str
|
40 |
|
41 |
# Gradio Interface
|
42 |
title = "Lean 4 Code Generation with TheoremLlama"
|