MCPcopy Create free account
hub / github.com/MARIO-Math-Reasoning/Super_MARIO / generate_postprocess

Method generate_postprocess

mcts_math/solver.py:129–174  ·  view source on GitHub ↗
(
        self, 
        outputs: List[List[RequestOutput]], 
        valid_solvers: List[BaseTree],
    )

Source from the content-addressed store, hash-verified

127 return prompts, prompts_span, valid_solvers, invalid_solvers
128
129 def generate_postprocess(
130 self,
131 outputs: List[List[RequestOutput]],
132 valid_solvers: List[BaseTree],
133 ) -> List[BaseTree]:
134 post_solvers = []
135 with ProcessPool(max_workers=min(len(valid_solvers), os.cpu_count())) as pool:
136 future = pool.map(self.__class__.processor, valid_solvers, outputs, timeout=TIMEOUT_SECONDS)
137 iterator = future.result()
138
139 if len(valid_solvers) > 100:
140 progress_bar = tqdm(total=len(valid_solvers), desc="Execute")
141 else:
142 progress_bar = None
143
144 while True:
145 try:
146 result = next(iterator)
147 post_solvers.append(result)
148 except StopIteration:
149 break
150 except TimeoutError as error:
151 post_solvers.append(None)
152 if self.config.verbose:
153 print(colored(f"{error}\n", ERROR_COLOR))
154 except SystemExit as error:
155 post_solvers.append(None)
156 if self.config.verbose:
157 print(colored(f"{error}\n", ERROR_COLOR))
158 except Exception as error:
159 if self.config.verbose:
160 print(colored(f"{error}\n", ERROR_COLOR))
161 post_solvers.append(None)
162 if progress_bar is not None:
163 progress_bar.update(1)
164
165 if progress_bar is not None:
166 progress_bar.close()
167
168 # update solvers
169 assert len(valid_solvers) == len(post_solvers), f"Data is not matched, {len(valid_solvers)} vs {len(post_solvers)}."
170 updated_solvers = [
171 post_solver if post_solver is not None else valid_solver
172 for post_solver, valid_solver in zip(post_solvers, valid_solvers)
173 ]
174 return updated_solvers
175
176 def value_preprocess(self, solvers: List[BaseTree]) -> Tuple[List[str], List[int]]:
177 prompts = []

Callers 1

solveMethod · 0.95

Calls 1

updateMethod · 0.80

Tested by

no test coverage detected