Skip to content

Correct metadata and docs our own merges made stale - #112

Merged
AlexanderFengler merged 2 commits into
mainfrom
chore/fix-stale-hf-metadata
Aug 11, 2026
Merged

Correct metadata and docs our own merges made stale#112
AlexanderFengler merged 2 commits into
mainfrom
chore/fix-stale-hf-metadata

Conversation

@AlexanderFengler

@AlexanderFengler AlexanderFengler commented Aug 10, 2026

Copy link
Copy Markdown
Member

Follow-ups from #108/#109/#110, plus the executable form of the ONNX contract.

The one with a deadline

Generated model cards defaulted to license: mit, but franklab/HSSM declares bsd-2-clause. The ecosystem's code is MIT; a model card describes the published artifact, so it follows the artifact repo. Left alone, the first automated publish would have stamped a contradicting license onto every card — annoying to retro-fix across 40 of them. Now one DEFAULT_LICENSE beside DEFAULT_REPO_ID.

Stale after our own merges

The contract, as a check instead of a paragraph

onnx/contract.py::assert_single_trial_contract replaces prose that four exporters each had to remember, and that was wrong where it was written down.

The invariant is exactly one thing: every input dim concrete. Rank is not part of it — it follows from how a tracer lowers a dense layer. torch.onnx.export on a rank-1 dummy gives rank-agnostic MatMul+Add (sbi, bayesflow); a (1, D) dummy, and jax2onnx always, gives Gemm, whose spec requires rank 2. Both load in HSSM and, measured under vmap+jit, run identically.

Verified against production — nothing changes for existing artifacts

Ran the new check against all 18 root artifacts on franklab/HSSM:

angle.onnx [1,7]   ddm.onnx [1,6]   weibull.onnx [1,8]   levy.onnx [1,7]
ornstein.onnx [1,7]   lca_no_bias_4.onnx [1,11]   race_no_bias_angle_4.onnx [1,10]   ...
contract violations among production artifacts: 0

All 18 are (1, D) Gemm+Tanh. So this encodes what production already is; it does not impose a new rule that existing files would fail. It also settles the rank question empirically: production has always been (1, D), so the doc was wrong about the live artifacts too.

Found while doing this — not fixed here

hssm.HSSM(model="ddm_sdv", loglik_kind="approx_differentiable") is broken for every user today. HSSM's modelconfig/ddm_sdv_config.py:40 asks for ddm_sdv.onnx, which does not exist in franklab/HSSM (404). Reproduced end to end. That is an HSSM/artifact issue, not this PR's, and it makes an obvious first backfill target for the pipeline.

Commands run

uv run pytest tests/ -q      # 270 passed, 9 skipped, 1 xfailed
uv run ruff check . && uv run ruff format --check .

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added the transform-jax-onnx command for native JAX/Flax-to-ONNX conversion.
    • Added validation for single-trial ONNX models, including dimensions, input width, runtime compatibility, and supported operations.
    • Added gonogo as a supported network type.
  • Improvements
    • Published model cards now use the BSD-2-Clause license by default.
    • Improved HuggingFace installation guidance and clarified supported network types.
    • Documented atomic publishing, overwrite protection, manifests, and optional model-card enforcement.

- Model cards defaulted to license 'mit', but franklab/HSSM declares
  bsd-2-clause. The code is MIT; a card describes the *artifact*, so it
  follows the artifact repo. One DEFAULT_LICENSE next to DEFAULT_REPO_ID.
  Verified against every published artifact before the first real publish.
- The 'install it with' hints named only pip. Reworded to give both, since
  the message reaches end users (who pip-installed) and developers (who
  did not). The repo's own uv rule carves out end-user install docs.
- CLI --network-type help still said 'lan, cpn, or opn' after gonogo was
  added; it now derives from VALID_NETWORK_TYPES so it cannot drift again.
- CLAUDE.md claimed jaxtrain has no ONNX export (false since the jax2onnx
  exporter), that model_card.yaml is required (false since it is
  generated), and that all exporters trace rank-1 (never true of the MLP
  exporter, and not true of the production artifacts).

Adds onnx/contract.py: assert_single_trial_contract, the executable form
of the rank paragraph. The invariant is concrete input dims; rank follows
from the tracer's lowering. Checked against all 18 production artifacts on
franklab/HSSM — every one passes, all (1, D) Gemm+Tanh — so this encodes
what production already is rather than imposing something new.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 10, 2026 02:04
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f48ffaca-42b6-4b62-a74c-4466aaab8f31

📥 Commits

Reviewing files that changed from the base of the PR and between bbd8ae5 and 42602a6.

📒 Files selected for processing (7)
  • src/lanfactory/hf/__init__.py
  • src/lanfactory/hf/model_card.py
  • src/lanfactory/onnx/__init__.py
  • src/lanfactory/onnx/contract.py
  • tests/hf/test_dual_layout.py
  • tests/hf/test_model_card.py
  • tests/onnx/test_contract.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/hf/test_dual_layout.py
  • src/lanfactory/onnx/init.py
  • src/lanfactory/hf/init.py
  • src/lanfactory/onnx/contract.py

📝 Walkthrough

Walkthrough

Changes

The pull request adds a single-trial ONNX contract validator with runtime and operator checks. It standardizes Hugging Face artifact licensing, improves installation guidance, derives CLI network types dynamically, and updates architecture documentation.

ONNX contract and export documentation

Layer / File(s) Summary
Single-trial ONNX contract
src/lanfactory/onnx/..., tests/onnx/test_contract.py
Adds and exports assert_single_trial_contract. The validator checks concrete positive dimensions, runtime loadability, input width, and allowed operators. Tests cover valid rank-1 and rank-2 inputs and rejected inputs.
ONNX architecture documentation
CLAUDE.md
Documents JAX ONNX export, exporter tracing ranks, the transform-jax-onnx entry point, and the single-trial validator.

Hugging Face publishing defaults and CLI guidance

Layer / File(s) Summary
Hugging Face license and publishing behavior
src/lanfactory/hf/..., tests/hf/..., tests/onnx/test_contract.py, CLAUDE.md
Adds the shared BSD-2-Clause default license and applies it to generated model cards. Documents atomic roots, manifests, overwrite protection, and model-card handling.
CLI network types and installation messages
src/lanfactory/cli/*_hf.py, src/lanfactory/hf/download.py, src/lanfactory/hf/upload.py, CLAUDE.md
Derives network-type help from VALID_NETWORK_TYPES. Updates installation commands to include quoted extras and uv sync --extra hf. Documents gonogo as supported.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant assert_single_trial_contract
  participant ONNXModel
  participant ONNXRuntime
  Test->>assert_single_trial_contract: provide ONNX path and contract options
  assert_single_trial_contract->>ONNXModel: load and inspect graph
  assert_single_trial_contract->>ONNXRuntime: create inference session
  ONNXRuntime-->>assert_single_trial_contract: input shape and runtime status
  assert_single_trial_contract-->>Test: metadata or AssertionError
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main purpose: correcting stale metadata and documentation after prior merges.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/fix-stale-hf-metadata

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lanfactory/hf/model_card.py`:
- Around line 15-16: Update ModelCardConfig.license and its docstring to use
DEFAULT_LICENSE instead of the hardcoded "mit" value, ensuring direct
ModelCardConfig() callers match YAML fallback and generated-card metadata.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ff07f9c-7e58-4741-ad3d-3efb2aed6125

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb5e39 and bbd8ae5.

📒 Files selected for processing (11)
  • CLAUDE.md
  • src/lanfactory/cli/download_hf.py
  • src/lanfactory/cli/upload_hf.py
  • src/lanfactory/hf/__init__.py
  • src/lanfactory/hf/download.py
  • src/lanfactory/hf/model_card.py
  • src/lanfactory/hf/upload.py
  • src/lanfactory/onnx/__init__.py
  • src/lanfactory/onnx/contract.py
  • tests/hf/test_dual_layout.py
  • tests/onnx/test_contract.py

Comment thread src/lanfactory/hf/model_card.py

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.

Pull request overview

This PR updates HuggingFace/model-card metadata and project documentation that became stale after recent merges, and introduces an executable check for the “single-trial ONNX contract” so exporters can validate artifacts via tests rather than prose.

Changes:

  • Add onnx/contract.py::assert_single_trial_contract plus a focused test suite to enforce “all input dims concrete” and optionally pin allowed op sets.
  • Fix HuggingFace model-card licensing defaults by introducing DEFAULT_LICENSE="bsd-2-clause" (matching franklab/HSSM) and using it when generating/loading model cards.
  • Refresh CLI help strings and CLAUDE.md documentation to reflect current supported network types and the ONNX export reality (including JAX → ONNX).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/onnx/test_contract.py Adds tests covering the executable ONNX “single-trial” contract.
tests/hf/test_dual_layout.py Adds a regression test ensuring generated model cards use the artifact repo license.
src/lanfactory/onnx/contract.py Implements assert_single_trial_contract using ONNX + ORT validation.
src/lanfactory/onnx/init.py Exposes the new contract helper from the lanfactory.onnx package.
src/lanfactory/hf/upload.py Uses DEFAULT_LICENSE for generated model cards; improves hf extra install guidance.
src/lanfactory/hf/model_card.py Uses DEFAULT_LICENSE as the fallback when loading model_card.yaml.
src/lanfactory/hf/download.py Improves hf extra install guidance.
src/lanfactory/hf/init.py Adds DEFAULT_LICENSE constant alongside DEFAULT_REPO_ID.
src/lanfactory/cli/upload_hf.py Makes --network-type help derived from VALID_NETWORK_TYPES; improves hf extra install guidance.
src/lanfactory/cli/download_hf.py Makes --network-type help derived from VALID_NETWORK_TYPES; improves hf extra install guidance.
CLAUDE.md Updates docs to reflect current ONNX export pipeline and contract details.

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

Comment on lines +56 to +62
for graph_input in model.graph.input:
for dim in graph_input.type.tensor_type.shape.dim:
assert dim.HasField("dim_value"), (
f"symbolic dim {dim.dim_param!r} in input {graph_input.name!r}: "
"HSSM's make_jax_func rejects dynamic axes at load, and a graph "
"that slips through returns wrong numbers rather than failing"
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed — added assert dim.dim_value > 0. You are right that HasField is true for an explicitly-set zero, and a zero axis is degenerate whether or not the producer meant it as 'unknown'. Test added.

Comment on lines 6 to 10
__all__ = [
"transform_to_onnx",
"transform_jax_to_onnx",
"transform_sbi_to_onnx",
"transform_bayesflow_to_onnx",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed — added to all (and moved the import above the block so it reads in declaration order).

Comment on lines +12 to +15
width = input_dims[-1] if isinstance(input_dims[-1], int) else 6
x = helper.make_tensor_value_info("x", TensorProto.FLOAT, list(input_dims))
y = helper.make_tensor_value_info("y", TensorProto.FLOAT, [1, 1])
w = helper.make_tensor(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed — the helper now declares [1] for rank-1 inputs and [1, 1] for rank-2. Relying on permissive checker behaviour in the tests for the checker was the wrong precedent.

Comment thread tests/hf/test_dual_layout.py Outdated
Comment on lines +9 to 13
# MIT, but a model card describes the published artifact, so it follows the
# artifact repo — auto-generated cards claiming MIT would contradict it.
DEFAULT_LICENSE = "bsd-2-clause"
# gonogo included: the trainers already build gonogo networks (cli/utils.py
# train_output_type_dict) and HSSM resolves "{model}_gonogo.onnx", so excluding

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed — DEFAULT_LICENSE added to all.

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/lanfactory/hf/download.py 100.00% <ø> (ø)
src/lanfactory/hf/model_card.py 100.00% <100.00%> (ø)
src/lanfactory/hf/upload.py 94.65% <100.00%> (ø)
src/lanfactory/onnx/contract.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

CodeRabbit was right that my license fix was incomplete. I changed the
YAML fallback and the generated card, but ModelCardConfig's own field
still defaulted to 'mit', so any direct caller of ModelCardConfig() would
still have minted a card contradicting the artifact repo. It now defaults
to DEFAULT_LICENSE, and two pre-existing tests that pinned 'mit' are
updated to the corrected contract (one keeps an explicit 'mit' to prove
an explicit licence still passes through untouched).

Copilot findings, all valid:
- assert_single_trial_contract accepted a dim_value of 0. HasField is
  true for an explicitly-set zero, which some producers use for
  'unknown' and which is a degenerate axis regardless. Now rejected,
  with a test.
- DEFAULT_LICENSE and assert_single_trial_contract were importable but
  missing from __all__.
- The contract test helper declared a [1, 1] output for the rank-1 input
  case, where MatMul actually yields rank-1. Leaning on a permissive
  checker in the tests for the checker is not a good look.
- The license test hard-coded the string twice; it now pins the literal
  once and checks the wiring against the constant.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 11, 2026 00:19

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/lanfactory/onnx/init.py:6

  • This intra-package import uses an absolute module path and a blanket # noqa: E402 even though imports are already at the top of the file. Using a relative import keeps this consistent with the other exports here and avoids suppressing lint unnecessarily.
from .transform_onnx import transform_to_onnx

from lanfactory.onnx.contract import assert_single_trial_contract  # noqa: E402

src/lanfactory/cli/upload_hf.py:36

  • The CLI help for --model-folder still claims the folder "should contain model_card.yaml", but upload_model can now generate a default card unless --require-model-card is set. This help text is misleading for end users and contradicts the new behavior.
        "--network-type",
        help=f"Network type: one of {', '.join(VALID_NETWORK_TYPES)}.",
    ),

@AlexanderFengler
AlexanderFengler merged commit a50850b into main Aug 11, 2026
10 checks passed
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.

2 participants