arabelatso commited on
Commit
95738df
·
verified ·
1 Parent(s): 2ea7a60

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +146 -0
README.md ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ base_model:
6
+ - meta-llama/Llama-3.1-8B-Instruct
7
+ ---
8
+
9
+ <p align="center">
10
+ <img width=20%" src="figures/logo.png">
11
+ </p>
12
+
13
+ ## Introduction
14
+
15
+ We present a fine-tuned model for formal verification tasks. It is fine-tuned in five formal specification languages (Cog, Dafny, Lean4, ACSL, and TLA) on six formal-verification-related tasks:
16
+
17
+ - **Requirement Analysis**: given requirements and description of the verification or modeling goals, decomposing the goal into detailed verification steps
18
+
19
+ - **Proof/Model Generation**: given requirements and description of the verification or modeling goals, writing formal proofs or models that can be verified by verifier/model checker.
20
+
21
+ - **Proof segment generation**
22
+
23
+ - **Proof Completion**: complete the given incomplete proofs or models
24
+
25
+ - **Proof Infilling**: filling in the middle of the given incomplete proofs or models
26
+
27
+ - **Code 2 Proof**: (Currently only support for ACSL whose specification is in form of code annotations) given the code under verification, generate the proof with the specifications
28
+
29
+ ## Application Scenario
30
+
31
+ <p align="center">
32
+ <img width=100%" src="figures/application.png">
33
+ </p>
34
+
35
+
36
+ ## Supported Formal Specification Languages
37
+
38
+ <p align="center">
39
+ <img width=100%" src="figures/examples.png">
40
+ </p>
41
+
42
+ ## Data Preparation Pipeline
43
+ <p align="center">
44
+ <img width=60%" src="figures/data-prepare.png">
45
+ </p>
46
+
47
+ ## Quickstart
48
+ Here provides a code snippet with apply_chat_template to show you how to load the tokenizer and model and how to inference fmbench.
49
+
50
+ ``` python
51
+ from transformers import AutoModelForCausalLM, AutoTokenizer
52
+
53
+ instruct = """
54
+ Translate the given requirement using TLA's syntax and semantics.
55
+ You only need to return the TLA formal specification without explanation.
56
+ """
57
+
58
+ input_text = """
59
+ An operation `LM_Inner_Rsp(p)` that represents a response process for a given parameter `p`. It satisfies the following conditions:
60
+ - The control state `octl[p]` is equal to `\"done\"`.
61
+ - The `Reply(p, obuf[p], memInt, memInt')` operation is executed.
62
+ - The control state `octl` is updated by setting the `p` index of `octl` to `\"rdy\"`.
63
+ - The variables `omem` and `obuf` remain unchanged.
64
+ """
65
+
66
+ model_name = "fm-universe/deepseek-coder-7b-instruct-v1.5-fma"
67
+
68
+ model = AutoModelForCausalLM.from_pretrained(
69
+ model_name, torch_dtype="auto", device_map="auto"
70
+ )
71
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
72
+
73
+ messages = [{"role": "user", "content": f"{instruct}\n{input_text}"}]
74
+
75
+ text = tokenizer.apply_chat_template(
76
+ messages, tokenize=False, add_generation_prompt=True
77
+ )
78
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
79
+
80
+ generated_ids = model.generate(**model_inputs, max_new_tokens=4096)
81
+ generated_ids = [
82
+ output_ids[len(input_ids) :]
83
+ for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
84
+ ]
85
+
86
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
87
+ print(response)
88
+ ```
89
+
90
+ ## Example of Offline Inference
91
+
92
+ vLLM supports offline inference.
93
+
94
+ ``` python
95
+ from vllm import LLM, SamplingParams
96
+
97
+ instruct = """
98
+ Translate the given requirement using TLA's syntax and semantics.
99
+ You only need to return the TLA formal specification without explanation.
100
+ """
101
+
102
+ input_text = """
103
+ An operation `LM_Inner_Rsp(p)` that represents a response process for a given parameter `p`. It satisfies the following conditions:
104
+ - The control state `octl[p]` is equal to `\"done\"`.
105
+ - The `Reply(p, obuf[p], memInt, memInt')` operation is executed.
106
+ - The control state `octl` is updated by setting the `p` index of `octl` to `\"rdy\"`.
107
+ - The variables `omem` and `obuf` remain unchanged.
108
+ """
109
+
110
+ model_name = "fm-universe/deepseek-coder-7b-instruct-v1.5-fma"
111
+
112
+ # Pass the default decoding hyperparameters
113
+ # max_tokens is for the maximum length for generation.
114
+ greed_sampling = SamplingParams(temperature=0, max_tokens=4096)
115
+
116
+ # load the model
117
+ llm = LLM(
118
+ model=model_name,
119
+ tensor_parallel_size=1,
120
+ max_model_len=4096,
121
+ enable_chunked_prefill=True,
122
+ # quantization="fp8", # Enabling FP8 quantization for model weights can reduce memory usage.
123
+ )
124
+
125
+ # Prepare chat messages
126
+ chat_message = [{"role": "user", "content": f"{instruct}\n{input_text}"}]
127
+
128
+ # Inference
129
+ responses = llm.chat(chat_message, greed_sampling, use_tqdm=True)
130
+
131
+ print(responses[0].outputs[0].text)
132
+ ```
133
+
134
+ ## Citation
135
+ ```
136
+ @misc{fmbench25jialun,
137
+ title={From Informal to Formal--Incorporating and Evaluating LLMs on Natural Language Requirements to Verifiable Formal Proofs},
138
+ author={Jialun Cao and Yaojie Lu and Meiziniu Li and Haoyang Ma and Haokun Li and Mengda He and Cheng Wen and Le Sun and Hongyu Zhang and Shengchao Qin and Shing-Chi Cheung and Cong Tian},
139
+ year={2025},
140
+ eprint={2501.16207},
141
+ archivePrefix={arXiv},
142
+ primaryClass={cs.AI},
143
+ url={https://arxiv.org/abs/2501.16207},
144
+ }
145
+
146
+ ```