ho22joshua commited on
Commit
0075ca0
·
1 Parent(s): 5ae003d

docs: add Hugging Face model card based on paper (#9)

Browse files

- docs: add Hugging Face model card (196e2e82ecc61b8fb16ce65877e43ec6126113b3)
- docs: reproduce paper in model card (76eff8f0d9f97c4952f8a8ad79ebf84c7f9b22b6)
- docs: preserve paper author affiliations (7f136d97ab4e8589ef03ffa8c9691875cbb3aa7c)

README.md CHANGED
The diff for this file is too large to render. See raw diff
 
README_PROJECT.md ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # GNN4Colliders
2
+
3
+ GNN4Colliders is a collider-machine-learning toolkit. The repository name
4
+ reflects its first production model family, ROOT-GNN; the Python package is
5
+ `gnn4colliders`, and the configuration identifier is `root_gnn`. Shared ROOT
6
+ ingestion, collider features, metadata, tasks, training, inference, and
7
+ distributed utilities are designed so that a future sequence model can reuse
8
+ them without requiring every event to be a graph.
9
+
10
+ ```text
11
+ ROOT files -> EventSample -> shared collider features
12
+ ├── GraphSample -> ROOT-GNN
13
+ └── future SequenceSample -> ROOT-Transformer
14
+ ```
15
+
16
+ The new implementation lives under [`src/gnn4colliders`](src/gnn4colliders/).
17
+ [`legacy/`](legacy/) is a frozen behavioral reference for parity work and
18
+ historical checkpoint investigation, not a supported runtime backend.
19
+
20
+ ## Installation
21
+
22
+ The supported development environment is Python 3.12 (`>=3.12,<3.13`). Core
23
+ development is supported on macOS and Linux:
24
+
25
+ ```bash
26
+ # macOS (Apple Silicon): CPU ROOT-GNN development and tests
27
+ uv sync --dev --extra root-gnn
28
+
29
+ # Linux x86_64 with an NVIDIA GPU: validated ROOT-GNN development
30
+ uv sync --dev --extra root-gnn
31
+ ```
32
+
33
+ The core package can be installed without DGL when only shared data or task
34
+ code is needed. ROOT-GNN models, graph construction, and ROOT-GNN parity tests
35
+ require the `root-gnn` extra. On Linux x86_64, it uses the validated CUDA 12.1
36
+ wheels configured in `pyproject.toml`; a compatible NVIDIA driver is still
37
+ required. On Apple Silicon macOS, it installs the CPU DGL wheel, supporting
38
+ local graph/cache development. The default ROOT-GNN backend performs training
39
+ with native PyTorch graph tensors, so it runs on Apple MPS, NVIDIA CUDA, and
40
+ CPU; DGL remains a cache and legacy-compatibility adapter. Do not add
41
+ site-specific CUDA, Slurm, or filesystem paths to model or task configuration.
42
+
43
+ Use the MPS profile on an Apple Silicon Mac:
44
+
45
+ ```bash
46
+ uv run gnn4colliders train environment=macos
47
+ ```
48
+
49
+ ## Data samples
50
+
51
+ ROOT inputs are available from the
52
+ [HWresearch/Delphes dataset](https://huggingface.co/datasets/HWresearch/Delphes).
53
+ Download the 64-event smoke-test sample with the Hugging Face CLI:
54
+
55
+ ```bash
56
+ hf download HWresearch/Delphes testing/ttH_NLO_64.root \
57
+ --repo-type dataset --local-dir data/raw
58
+ ```
59
+
60
+ The sample is `data/raw/testing/ttH_NLO_64.root`, has tree name `output`, and
61
+ is suitable for checking the prepare/train workflow. The dataset also provides
62
+ larger process-specific ROOT samples under `samples/`, derived datasets under
63
+ `derived/`, and analysis-specific ntuples under `analyses/`. These data are
64
+ intentionally ignored by Git; inspect a selected ROOT file's tree and branches
65
+ before writing its preparation configuration.
66
+
67
+ ## Quick start
68
+
69
+ Prepare a graph cache from a ROOT tree. The feature specifications below are
70
+ illustrative placeholders; replace them with the branches in the input tree.
71
+ The full preparation interface is documented in
72
+ [`docs/configuration.md`](docs/configuration.md).
73
+
74
+ ```bash
75
+ uv run gnn4colliders prepare \
76
+ data.files=[data/events.root] \
77
+ data.tree_name=Events \
78
+ data.cache.path=cache/events.pt \
79
+ 'data.feature_branches=[["jet_pt"],["jet_eta"],["jet_phi"],CALC_E,[1.0],[0.0],NODE_TYPE]' \
80
+ data.object_types=[vector] \
81
+ data.scales=[1,1,1,1,1,1,1]
82
+ ```
83
+
84
+ Train, evaluate, and predict from that cache:
85
+
86
+ ```bash
87
+ uv run gnn4colliders train \
88
+ data.cache.path=cache/events.pt \
89
+ trainer.max_epochs=1 \
90
+ environment.output_root=outputs/pretraining_multiclass
91
+
92
+ uv run gnn4colliders evaluate \
93
+ data.cache.path=cache/events.pt \
94
+ inference.checkpoint=outputs/pretraining_multiclass/checkpoints/epoch_0000.pt
95
+
96
+ uv run gnn4colliders predict \
97
+ data.cache.path=cache/events.pt \
98
+ inference.checkpoint=outputs/pretraining_multiclass/checkpoints/epoch_0000.pt \
99
+ inference.output=outputs/pretraining_multiclass/predictions.npz
100
+ ```
101
+
102
+ For a dependency-complete, temporary-data version of this flow, run
103
+ `uv run python scripts/dev/smoke_end_to_end.py`.
104
+
105
+ ## Core concepts
106
+
107
+ `EventSample` is the architecture-neutral event boundary. It contains the
108
+ selected `objects`, `label`, `global_features`, and named `EventMetadata`.
109
+ Metadata includes `fold`, `weight`, and stable `sample_id`; callers should not
110
+ interpret public `tracking[:, N]` columns. Legacy tracking mappings exist only
111
+ at compatibility boundaries.
112
+
113
+ The ROOT-GNN adapter converts shared features to a directed, fully connected
114
+ graph with no self-loops: an event with `N` nodes has `N * (N - 1)` edges.
115
+ Node columns are, in order, `pt`, `eta`, `phi`, `energy`, `btag`, `charge`,
116
+ and `node_type`. Edge columns are `deta`, wrapped `dphi`, and `dR`.
117
+ Object collections are concatenated in configured object-type order. The
118
+ compatibility energy is `pt * cosh(eta)` before per-column scaling.
119
+
120
+ `GraphSampleCache` stores processed graph samples and schema metadata. It is a
121
+ Level-2 graph cache, not the universal event cache. Feature, graph, and cache
122
+ schema versions are checked when loading; incompatible versions fail before
123
+ training.
124
+
125
+ ## ROOT-GNN training and transfer
126
+
127
+ `EdgeNetwork` encodes node, edge, and global features, performs iterative
128
+ edge/node/global message passing, decodes a graph representation, and applies
129
+ the classifier. Its output is raw logits; sigmoid or softmax is task-owned.
130
+
131
+ Multiclass pretraining uses the semantic `model=root_gnn/edge_network` and
132
+ `task=pretraining_multiclass` groups:
133
+
134
+ ```bash
135
+ uv run gnn4colliders train \
136
+ data.cache.path=cache/events.pt \
137
+ model=root_gnn/edge_network task=pretraining_multiclass \
138
+ trainer.max_epochs=20 data.batch_size=64 \
139
+ environment.output_root=outputs/pretraining_multiclass
140
+ ```
141
+
142
+ Fine-tuning is a separate workflow. It loads a pretrained backbone, replaces
143
+ the classifier, and creates a new task/head optimizer:
144
+
145
+ ```bash
146
+ uv run gnn4colliders train \
147
+ data.cache.path=cache/target.pt \
148
+ model=root_gnn/fine_tuned_edge_network \
149
+ task=binary_classification \
150
+ checkpoint.pretrained=/path/to/pretrained.pt \
151
+ model.freeze_backbone=true \
152
+ trainer.max_epochs=10
153
+ ```
154
+
155
+ Set `model.freeze_backbone=false` to train the reused backbone as well.
156
+ Transfer learning is not resume training:
157
+
158
+ | Workflow | Meaning | Restored state |
159
+ | --- | --- | --- |
160
+ | Resume | Continue the same task/run | model, optimizer, scheduler, trainer, early stopping, and RNG state when present |
161
+ | Transfer | Start a new task from a pretrained backbone | model weights only; new classifier and optimizer |
162
+
163
+ Resume example:
164
+
165
+ ```bash
166
+ uv run gnn4colliders train \
167
+ data.cache.path=cache/events.pt \
168
+ checkpoint.resume=outputs/pretraining_multiclass/checkpoints/epoch_0000.pt \
169
+ trainer.max_epochs=20
170
+ ```
171
+
172
+ Validation is evaluated each epoch and drives scheduling/early stopping;
173
+ `test` remains held out. Evaluation computes task metrics over the complete
174
+ selected split, including weighted ROC AUC where defined:
175
+
176
+ ```bash
177
+ uv run gnn4colliders evaluate \
178
+ data.cache.path=cache/events.pt \
179
+ inference.split=test \
180
+ inference.checkpoint=/path/to/checkpoint.pt
181
+ ```
182
+
183
+ Prediction writes a named compressed NPZ. Labeled data includes `labels`;
184
+ `fold` and `weight` are included when available. Every result includes
185
+ `sample_id`, `logits`, `scores`, and `predictions`:
186
+
187
+ ```bash
188
+ uv run gnn4colliders predict \
189
+ data.cache.path=cache/events.pt \
190
+ inference.checkpoint=/path/to/checkpoint.pt \
191
+ inference.output=outputs/predictions.npz
192
+ ```
193
+
194
+ Optional Python-level ROOT writing is provided by
195
+ `gnn4colliders.inference.write_root_scores`. It clones the selected tree,
196
+ adds `score` (or `score_class_N`), and writes `selection_pass`; IDs ending in
197
+ `:<entry>` preserve alignment and unselected entries receive NaN scores. The
198
+ CLI currently exposes NPZ output only.
199
+
200
+ The supported legacy checkpoint, metadata, and output boundary is documented
201
+ in [`docs/compatibility.md`](docs/compatibility.md). New code should use named
202
+ metadata fields; positional tracking is accepted only by the explicit
203
+ compatibility adapter.
204
+
205
+ ### ONNX export
206
+
207
+ Install the optional export dependencies and export a prepared graph-cache
208
+ checkpoint with numerical ONNX validation:
209
+
210
+ ```bash
211
+ uv sync --extra root-gnn --extra onnx
212
+ uv run gnn4colliders export \
213
+ export.checkpoint=/path/to/checkpoint.pt \
214
+ export.output=model.onnx \
215
+ data.cache.path=/path/to/graph-cache.pt
216
+ ```
217
+
218
+ The model accepts processed graph tensors and returns raw logits. See
219
+ [`docs/export.md`](docs/export.md) for the tensor contract and limitations.
220
+
221
+ ## Configuration and environments
222
+
223
+ Hydra groups are `data`, `model`, `task`, `trainer`, `checkpoint`,
224
+ `inference`, `environment`, and `distributed`. Use configuration for a new
225
+ experiment and Python for new behavior. Examples:
226
+
227
+ ```bash
228
+ uv run gnn4colliders train trainer.max_epochs=50 data.batch_size=64
229
+ uv run gnn4colliders train environment=perlmutter environment.device=cuda
230
+ uv run gnn4colliders train distributed=ddp environment=perlmutter
231
+ ```
232
+
233
+ Each run writes a resolved configuration to
234
+ `<environment.output_root>/resolved_config.yaml`. See
235
+ [`docs/configuration.md`](docs/configuration.md) for the group reference and
236
+ [`docs/perlmutter.md`](docs/perlmutter.md) for launch examples.
237
+
238
+ ## Distributed execution and reproducibility
239
+
240
+ Launch DDP with `torchrun` or the provided Slurm wrappers. `data.batch_size`
241
+ and `data.num_workers` are per process, so the ordinary effective batch size
242
+ is `batch_size * world_size`. Training shards may be padded for equal steps;
243
+ validation and prediction are unpadded. Rank 0 writes shared checkpoints,
244
+ configs, and predictions, and metrics/results are gathered across ranks.
245
+
246
+ The configured seed controls initialization and deterministic local loader
247
+ ordering; distributed process seeds are rank-offset and samplers use
248
+ `set_epoch`. CPU runs are reproducible for fixed inputs and environment. GPU
249
+ kernels, DGL, and distributed scheduling can remain nondeterministic, so the
250
+ project does not promise bitwise GPU reproducibility.
251
+
252
+ ## Development and validation
253
+
254
+ ```bash
255
+ uv run pytest
256
+ uv run pytest tests/unit
257
+ GNN4COLLIDERS_REQUIRE_ROOT_GNN=1 uv run pytest tests/parity -v
258
+ uv run ruff check .
259
+ uv run ruff format --check .
260
+ uv run python benchmarks/benchmark_preprocessing.py
261
+ uv run python benchmarks/benchmark_training.py --device cpu
262
+ ```
263
+
264
+ Unit tests cover isolated components, integration tests cover small workflows,
265
+ and parity tests compare deterministic behavior with the frozen legacy
266
+ reference. Performance guidance and measured caveats are in
267
+ [`docs/performance.md`](docs/performance.md) and
268
+ [`benchmarks/README.md`](benchmarks/README.md).
269
+ See [`docs/testing.md`](docs/testing.md) for test layers, optional dependency
270
+ markers, and package smoke validation.
271
+
272
+ ## Architecture and migration status
273
+
274
+ See [`docs/architecture.md`](docs/architecture.md) for responsibility
275
+ boundaries and the future sequence-model extension point. See
276
+ [`docs/migration.md`](docs/migration.md) for the migration matrix,
277
+ intentional redesigns, compatibility limits, and deferred work.
278
+
279
+ ROOT-GNN v1 covers ROOT preparation, validated feature/graph/model/task
280
+ behavior, training, fine-tuning, checkpoint resume, evaluation, prediction,
281
+ single-process/DDP execution, and validated ONNX export. Streaming distributed
282
+ output, legacy cleanup, and ROOT-Transformer remain follow-up work.
paper.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9587a5b67b73dfc0f88b2a641b98410623a592d47cedd8fc71b35d28e9e1dfbc
3
+ size 142839
plots/cka_layerwise.svg ADDED
plots/hyperparameter_optimization.svg ADDED
plots/trainingtime.svg ADDED