Download tasks/bibliographic_archive/solution/reference/main.py from Tokenwave-AI/REE: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/datasets/Tokenwave-AI/REE/resolve/main/tasks/bibliographic_archive/solution/reference/main.py
- Command line
-
hf download hf://datasets/Tokenwave-AI/REE/tasks/bibliographic_archive/solution/reference/main.py
-
curl -L -o main.py https://huggingface.co/datasets/Tokenwave-AI/REE/resolve/main/tasks/bibliographic_archive/solution/reference/main.py
2 kB
| """Task entry point: SIGN feature computation and saved-model inference.""" | |
| from __future__ import annotations | |
| import time | |
| STARTED = time.monotonic() | |
| import json | |
| import os | |
| from pathlib import Path | |
| import resource | |
| import sys | |
| import numpy as np | |
| sys.path.insert(0, os.environ["CORE_DIR"]) | |
| from interface.data import read, write | |
| from graph import sign_features | |
| from training import HOPS, predict | |
| from checkpoint import load | |
| def main(): | |
| meta, arrays = read(sys.argv[1]) | |
| query = np.asarray(arrays["query"], dtype=np.int64) | |
| if not len(query): | |
| write(sys.argv[2], query, np.empty(0, dtype=np.int64)) | |
| return | |
| model, metadata = load(Path(__file__).resolve().parent / "model.npz") | |
| if metadata["input_width"] != arrays["features"].shape[1]: | |
| raise ValueError("Input feature width differs from the fitted SIGN model") | |
| if int(meta["classes"]) > metadata["classes"]: | |
| raise ValueError("Input label domain exceeds the fitted SIGN model") | |
| features = sign_features(meta, arrays, hops=HOPS) | |
| preprocessing_seconds = time.monotonic() - STARTED | |
| del arrays | |
| predictions = predict(model, features, query, classes=int(meta["classes"])) | |
| write(sys.argv[2], query, predictions) | |
| report = { | |
| "method": "DGL SIGN; saved-model inference", | |
| "checkpoint_selected_epoch": metadata["training"]["selected_epoch"], | |
| "checkpoint_reduced_data_smoke": metadata["training"]["reduced_data_smoke"], | |
| "preprocessing_seconds": preprocessing_seconds, | |
| "elapsed_seconds": time.monotonic() - STARTED, | |
| "threads": int(os.environ.get("OPENBLAS_NUM_THREADS", "4")), | |
| "peak_rss_kib": resource.getrusage(resource.RUSAGE_SELF).ru_maxrss, | |
| "query_count": len(query), "optimizer_steps_at_prediction": 0, | |
| } | |
| (Path(sys.argv[2]) / "inference_report.json").write_text( | |
| json.dumps(report, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps(report), flush=True) | |
| if __name__ == "__main__": | |
| main() | |