Skip to content

Add MatterGen crystal diffusion score-core export - #731

Open
justinchuby wants to merge 2 commits into
mainfrom
justinchuby-add-mattergen-crystal-diffusion
Open

Add MatterGen crystal diffusion score-core export#731
justinchuby wants to merge 2 commits into
mainfrom
justinchuby-add-mattergen-crystal-diffusion

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

  • Adds pinned microsoft/mattergen@5244495dd9a979ff71abc7548a0b14b9deb0069a support for all released checkpoint families.
  • Exports the deterministic float32 GemNet-T score core with explicit periodic graph and condition-port ABI.
  • Adds strict Lightning checkpoint routing, CLI support, source-derived L3/L4 score parity, and a real weighted L5 host-sampling golden.

Runtime boundary

ModelPackage remains deliberately partial (end_to_end_runnable: false): periodic neighbor/triplet construction, D3PM/VE/VP scheduling, classifier-free guidance, and crystal validation are host-owned. MatterGenHostSampler supplies the source-faithful CPU host loop around an explicit ONNX Runtime callback; ONNX Runtime GenAI is not presented as an end-to-end runtime.

Evidence

  • Pins MatterGen v1.0.3 source commit 842ffe735f7d06cec89d56aa23d9f001e1124b30.
  • Builds full pinned Hydra configs for all nine official families.
  • Validates source/ORT outputs at two timesteps, periodic translation/permutation invariance, batched PBC graph ordering, D3PM RNG behavior, and conditional/unconditional dft_band_gap.
  • Runs the released 1,000-step schedule using real mp_20_base ONNX weights and validates the committed deterministic crystal artifact.

Limitations

Only CPU/default float32 score-core execution is assessed. f16, bf16, CUDA, and GenAI are explicitly refused. Pymatgen Structure/CIF serialization remains application-owned; the host validates a dependency-free structural artifact.

justinchuby and others added 2 commits September 4, 2026 11:06
Validate the official mp_20_base score core against pinned MatterGen source and a source-derived golden fixture. Cover PBC invariance and the dft_band_gap adapter's conditional and unconditional score paths.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 332c98c9-cf56-4bab-8552-ac1b6d730556
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Export the pinned official MatterGen GemNet-T score core with Hydra configuration parsing, exhaustive checkpoint routing, a documented dynamic PBC graph ABI, and CLI integration. Add a source-faithful CPU host sampler with the released D3PM/VE/VP schedule and a real ONNX sampling golden while explicitly retaining host orchestration in the partial export report.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 332c98c9-cf56-4bab-8552-ac1b6d730556
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby
justinchuby requested review from a team and a lite review from Copilot September 4, 2026 18:25
@@ -0,0 +1,183 @@
# Copyright (c) Microsoft Corporation.
@@ -0,0 +1,187 @@
# Copyright (c) Microsoft Corporation.
@@ -0,0 +1,187 @@
# Copyright (c) Microsoft Corporation.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

from __future__ import annotations
@@ -0,0 +1,323 @@
# Copyright (c) Microsoft Corporation.
@@ -0,0 +1,1206 @@
# Copyright (c) Microsoft Corporation.
self.div_term = nn.Parameter([hidden_dim // 2])
# Source registers div_term as a float32 buffer. It must not be
# demoted with model weights when the exporter requests fp16/bf16.
setattr(self.div_term, "_keep_float32", True)
@@ -0,0 +1,208 @@
# Copyright (c) Microsoft Corporation.
@@ -0,0 +1,208 @@
# Copyright (c) Microsoft Corporation.

"""Task wiring for the host-orchestrated MatterGen GemNet-T score core."""

from __future__ import annotations
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing 8c38c0692771e3

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 68 68 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 66 66 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 105 105 +0.0%
gpt2 model_size_bytes 324 KB 324 KB +0.0%
gpt2 num_nodes 54 54 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 60 60 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 56 56 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 94 94 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 58 58 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 54 54 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 60 60 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 56 56 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 265 265 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 127 127 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 450 450 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 176 176 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.


def run(
self, output_names: Sequence[str] | None, input_feed: Mapping[str, np.ndarray]
) -> Sequence[np.ndarray]: ...

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are a couple of concrete robustness issues (artifact validation in the parity fixture and CLI error handling for save-time failures) that should be fixed before merging.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds a first-class Mobius integration for the pinned microsoft/mattergen release by exporting the deterministic float32 GemNet‑T score core to standard ONNX, while explicitly keeping periodic graph construction and the diffusion/sampling loop as host-owned responsibilities (with a provided CPU host runtime).

Changes:

  • Add MatterGen score-core model + MatterGenScoreTask exporting an explicit periodic-graph + condition-port ABI, plus strict Lightning checkpoint routing.
  • Add a source-faithful CPU host runtime (MatterGenHostSampler) including periodic graph/triplet construction and the full 1,000-step schedule around a pluggable score callback.
  • Add CLI entrypoint support (--mattergen-checkpoint), documentation, and L3/L4/L5 parity + golden tests.
File summaries
File Description
tests/integration/mattergen_parity_test.py Adds pinned-source L3/L4 parity and an L5 host-sampling golden against real weights.
tests/cli_test.py Adds CLI routing/validation tests for MatterGen-specific build behavior.
testdata/golden/diffusion/mattergen-mp20-score.json Adds one-step real-weight score-core golden provenance + outputs.
testdata/golden/diffusion/mattergen-mp20-host-sample.json Adds deterministic 1,000-step host-sampling golden artifact provenance.
src/mobius/tasks/_mattergen.py Introduces MatterGenScoreTask wiring the explicit host ABI and partial export report.
src/mobius/tasks/init.py Registers MatterGenScoreTask and task name mattergen-score.
src/mobius/models/mattergen.py Declares the GemNet‑T score-core graph and strict preprocess/weight-routing behavior.
src/mobius/models/init.py Exposes MatterGen models from the public models package.
src/mobius/integrations/mattergen/_weights.py Adds fail-closed Lightning checkpoint loading + exact initializer routing.
src/mobius/integrations/mattergen/_weights_test.py Unit tests for strict weight loading, routing, and reporting.
src/mobius/integrations/mattergen/_runtime.py Adds the host-owned periodic graph + sampler runtime and ORT callback adapter.
src/mobius/integrations/mattergen/_runtime_test.py Unit tests for periodic graph ordering, CFG call order, and sampler determinism.
src/mobius/integrations/mattergen/_contract.py Defines pinned hub/source commits, host-owned steps, allowlists, and validation helpers.
src/mobius/integrations/mattergen/_contract_test.py Validates the pinned contract constants and helper semantics.
src/mobius/integrations/mattergen/_configs.py Parses expanded Hydra configs into a typed MatterGenConfig without Hydra deps.
src/mobius/integrations/mattergen/_builder.py Adds pinned builder (build_mattergen) supporting Hub or safe local checkpoint roots.
src/mobius/integrations/mattergen/_builder_test.py Tests config parsing, port ABI, pinned revision enforcement, and family coverage.
src/mobius/integrations/mattergen/init.py Adds a lazy public API surface for MatterGen integration symbols.
src/mobius/main.py Adds MatterGen CLI routing and a new --mattergen-checkpoint flag.
src/mobius/init.py Exposes build_mattergen at the package top level.
pyproject.toml Adds PyYAML dependency used for loading pinned Hydra configs.
docs/model-catalog.md Documents MatterGen under periodic crystal diffusion exports.
docs/mattergen.md Adds detailed ABI, host/runtime boundary, and build instructions for MatterGen.
docs/index.md Adds MatterGen docs page to the documentation index.
Review details
  • Files reviewed: 24/24 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mobius/__main__.py
Comment on lines +384 to +396
try:
pkg = build_mattergen(
mattergen_source,
checkpoint=args.mattergen_checkpoint or "mp_20_base",
revision=revision,
dtype=dtype_override,
load_weights=load_weights,
execution_provider=execution_provider,
)
except ValueError as error:
raise SystemExit(f"Error: {error}") from error
_save_package(pkg, output_dir, args, optimize, component_filter)
return
Comment on lines +156 to +162
path = Path(raw_path)
if not path.is_file() and environment_variable == _SOURCE_DIR_ENV:
if not path.is_dir():
pytest.skip(f"{environment_variable} is not a readable source directory: {path}")
elif not path.is_file():
pytest.skip(f"{environment_variable} is not a readable checkpoint: {path}")
return path
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 8c38c0692771e3

Model Sub-model Changes Status
bert (feature-extraction) model 0
falcon model 0
gemma2 model 0
gemma4 (gemma4) decoder 0
gemma4 (gemma4) embedding 0
gemma4 (gemma4) vision_encoder 0
gemma4_text model 0
gpt2 model 0
llama model 0
llama (static-cache) model 0
mamba (ssm-text-generation) model 0
phi3 model 0
phi3 (static-cache) model 0
qwen model 0
qwen (static-cache) model 0
qwen2 model 0
qwen2 (static-cache) model 0
qwen2_moe model 0
qwen2_moe (static-cache) model 0
qwen3 model 0
qwen3 (static-cache) model 0
qwen3_5_moe (hybrid-text-generation) model 0
qwen3_5_text (hybrid-text-generation) model 0
qwen3_5_vl (hybrid-qwen-vl) decoder 0
qwen3_5_vl (hybrid-qwen-vl) embedding 0
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0
qwen3_moe model 0
qwen3_moe (static-cache) model 0
qwen3_next (hybrid-text-generation) model 0
t5 (seq2seq) decoder 0
t5 (seq2seq) encoder 0
whisper (speech-to-text) decoder 0
whisper (speech-to-text) encoder 0

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants