Views
No views yet

transformers library. You can load and use it for text generation tasks, particularly for generating Dafny code.1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4# Replace with the specific model checkpoint you want to use, e.g., "Veri-Code/sft_0.5B" or "Veri-Code/reform-qwen2-7b-sft"
5model_name = "Veri-Code/sft_0.5B"
6
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(
9 model_name,
10 torch_dtype=torch.bfloat16, # Use bfloat16 for better performance if supported, otherwise torch.float16
11 device_map="auto" # Automatically loads the model across available devices (e.g., multiple GPUs)
12)
13
14model.eval() # Set model to evaluation mode
15
16# Example: Generate Dafny code for a simple function
17prompt = """
18method Add(x: int, y: int) returns (sum: int)
19 ensures sum == x + y
20{
21"""
22
23print(f"Input Prompt:
24{prompt}")
25
26inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
27
28# Generate continuation of the code
29with torch.no_grad():
30 outputs = model.generate(
31 **inputs,
32 max_new_tokens=100, # Generate up to 100 new tokens
33 do_sample=True,
34 temperature=0.7, # Adjust for more/less creative outputs
35 top_p=0.9 # Adjust for nucleus sampling
36 )
37
38generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
39print(f"Generated Dafny Code:
40{generated_text}")1@misc{yan2025reformreducinghuman,
2 title={Re:Form -- Reducing Human Priors in Scalable Formal Software Verification with RL in LLMs: A Preliminary Study on Dafny},
3 author={Chuanhao Yan and Fengdi Che and Xuhan Huang and Xu Xu and Xin Li and Yizhi Li and Xingwei Qu and Jingzhe Shi and Zhuangzhuang He and Chenghua Lin and Yaodong Yang and Binhang Yuan and Hang Zhao and Yu Qiao and Bowen Zhou and Jie Fu},
4 year={2025},
5 eprint={2507.16331},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2507.16331},
9}