Datasets:
Download code/evaluation-code/v0.2-0c2690ae/tests/prover_gpu/clauses.py from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 3.83 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/tests/prover_gpu/clauses.py
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/evaluation-code/v0.2-0c2690ae/tests/prover_gpu/clauses.py
-
curl -L -o clauses.py https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/tests/prover_gpu/clauses.py
3.83 kB
| """实际检查名与缺失约束:python3 clauses.py <输出.json> <剧本目录>…。 | |
| CLAUSE_VERSIONS=版本,… 可用于小样;默认检查全部版本,每版每剧本防卡死限 600 秒。 | |
| """ | |
| import collections | |
| import json | |
| import os | |
| from pathlib import Path | |
| import signal | |
| import sys | |
| import time | |
| from embodied_pipeline.prover import interp | |
| def main(): | |
| out, dirs = sys.argv[1], sys.argv[2:] | |
| if not dirs: | |
| raise SystemExit('至少提供一个剧本目录') | |
| root = Path(interp.__file__).resolve().parents[2] | |
| ids = {c['id'] for c in json.loads((root / 'spec/questions/constraints.json').read_text())['constraints']} | |
| plans = interp.plans()[0] | |
| versions = os.environ.get('CLAUSE_VERSIONS', '').split(',') if os.environ.get('CLAUSE_VERSIONS') else sorted(plans) | |
| if len(set(versions)) != len(versions) or any(v not in plans for v in versions): | |
| raise SystemExit('版本未知或重复') | |
| seen, missing, errors, timeouts = {}, {}, {}, [] | |
| current = [None] | |
| add0, reject0 = interp.Tally.add, interp.Tally.reject | |
| def add(self, shape, checks, score, package, parts=None): | |
| checks = list(checks) | |
| seen[current[0]].update(name for name, _ in checks + self._universal(parts)) # 出包口统一加的条款也算(S1) | |
| return add0(self, shape, checks, score, package, parts=parts) | |
| def reject(self, reason, count): | |
| seen[current[0]].add(reason) | |
| return reject0(self, reason, count) | |
| def alarm(*_): | |
| raise TimeoutError() | |
| def save(): | |
| names = dict(sorted(collections.Counter(name for names in seen.values() for name in names).items())) | |
| bad = [name for name in names if name.split(':')[0] not in ids and not name.startswith('blocked:')] | |
| result = dict(names=names, bad=bad, check_missing={k: sorted(v) for k, v in sorted(missing.items())}, | |
| versions={k: sorted(v) for k, v in seen.items()}, expected=len(versions)*len(dirs), | |
| completed=completed, timeouts=timeouts, errors=errors) | |
| Path(out).write_text(json.dumps(result, ensure_ascii=False, indent=2) + '\n') | |
| return result | |
| completed, start = 0, time.monotonic() | |
| previous = signal.signal(signal.SIGALRM, alarm) | |
| interp.Tally.add, interp.Tally.reject = add, reject | |
| try: | |
| for version in versions: | |
| current[0] = version | |
| seen[version] = set() | |
| for directory in dirs: | |
| cpu, wall = time.process_time(), time.monotonic() | |
| signal.alarm(600) | |
| try: | |
| result = interp.run(directory, version) | |
| seen[version].update(k for k in (result.get('reject_reasons') or {}) if k.startswith('blocked:')) | |
| for cid in result.get('check_missing', []): | |
| missing.setdefault(cid, set()).add(version) | |
| completed += 1 | |
| except TimeoutError: | |
| timeouts.append([version, directory]) | |
| print(f'{version}@{directory}: CPU={time.process_time()-cpu:.3f}s wall={time.monotonic()-wall:.3f}s', file=sys.stderr) | |
| except Exception as exc: | |
| errors[f'{version}@{directory}'] = f'{type(exc).__name__}: {exc}' | |
| finally: | |
| signal.alarm(0) | |
| save() | |
| finally: | |
| interp.Tally.add, interp.Tally.reject = add0, reject0 | |
| signal.signal(signal.SIGALRM, previous) | |
| result = save() | |
| print(f"实际条款:{completed}/{result['expected']} 次,{len(result['names'])} 名,非法 {len(result['bad'])},超时 {len(timeouts)},报错 {len(errors)},{time.monotonic()-start:.1f} s") | |
| return int(bool(result['bad'] or timeouts or errors)) | |
| if __name__ == '__main__': | |
| sys.exit(main()) | |