Skip to content

Jaxtyping Shape Contracts - #748

Queued
jchmura-sc wants to merge 30 commits into
mainfrom
jchmura/jaxtyping-shape-contracts
Queued

Jaxtyping Shape Contracts#748
jchmura-sc wants to merge 30 commits into
mainfrom
jchmura/jaxtyping-shape-contracts

Conversation

@jchmura-sc

@jchmura-sc jchmura-sc commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Purpose of this PR

This PR adds targeted, runtime-checkable tensor contracts for: loader and sampler inputs, public model forward and decode methods, loss interfaces, and task-result containers.

Jaxtyping lets an annotation declare tensor dtype, rank, fixed dimensions, and relationships between named dimensions. For example, Float[Tensor, "queries embedding_dim"] and Float[Tensor, "candidates embedding_dim"] require matching embedding_dim; decoder output Float[Tensor, "queries candidates"] then documents both output axes. This makes malformed tensors fail close to the boundary.

The contracts are intentionally test-only. Unit, integration, and E2E launchers install a Jaxtyping hook before test discovery. Listed modules imported afterwards are instrumented; arguments are checked before execution and returns afterwards. An uncaught violation raises jaxtyping.TypeCheckError, which fails the test command. Production execution does not enable this mechanism, and this PR does not expose it as a user API.

@jchmura-sc jchmura-sc self-assigned this Aug 14, 2026
Comment thread tests/unit/distributed/sampler_test.py
Comment thread gigl/distributed/dist_ppr_sampler.py
Comment thread tests/unit/nn/models_test.py

@kmontemayor2-sc kmontemayor2-sc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Neat! Thanks for exploring Jacob :) I left some comments :)

I guess for this we'd need to be careful that we only enable runtime shape checking for tests?

Comment thread gigl/distributed/dist_ppr_sampler.py
Comment thread gigl/distributed/sampler.py
Comment thread tests/integration/main.py
Comment thread tests/test_assets/runtime_type_checking.py Outdated
Comment thread gigl/distributed/base_sampler.py
Comment thread pyproject.toml Outdated
Comment thread tests/unit/distributed/sampler_test.py
Comment thread tests/unit/distributed/sampler_test.py
Comment thread tests/test_assets/runtime_type_checking.py Outdated
@jchmura-sc

Copy link
Copy Markdown
Collaborator Author

/unit_test

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

GiGL Automation

@ 20:21:42UTC : 🔄 Scala Unit Test started.

@ 20:32:44UTC : ✅ Workflow completed successfully.

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

GiGL Automation

@ 20:21:43UTC : 🔄 C++ Unit Test started.

@ 20:23:48UTC : ✅ Workflow completed successfully.

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

GiGL Automation

@ 20:21:45UTC : 🔄 Python Unit Test started.

@ 21:44:34UTC : ✅ Workflow completed successfully.

@jchmura-sc
jchmura-sc marked this pull request as ready for review August 18, 2026 22:25
@jchmura-sc

Copy link
Copy Markdown
Collaborator Author

/unit_test

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

GiGL Automation

@ 17:30:27UTC : 🔄 Scala Unit Test started.

@ 17:40:16UTC : ✅ Workflow completed successfully.

@github-actions

Copy link
Copy Markdown
Contributor

GiGL Automation

@ 17:30:30UTC : 🔄 Python Unit Test started.

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

GiGL Automation

@ 17:30:31UTC : 🔄 C++ Unit Test started.

@ 17:32:47UTC : ✅ Workflow completed successfully.

@kmontemayor2-sc kmontemayor2-sc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Neat! I think I'm fine with these changes:)

BTW, do you know how much more coverage is untyped?

Can we get a review from @yliu2-sc for the GT shapes as well?

Comment thread gigl/common/data/export.py
Comment thread gigl/distributed/base_sampler.py
Comment thread tests/test_assets/runtime_type_checking.py Outdated
@jchmura-sc jchmura-sc changed the title Add test-time tensor shape contracts Jaxtyping Shape Contracts Aug 20, 2026
@jchmura-sc
jchmura-sc added this pull request to the merge queue Aug 20, 2026
Any commits made after this event will not be merged.
@jchmura-sc

Copy link
Copy Markdown
Collaborator Author

BTW, do you know how much more coverage is untyped?

@kmontemayor2-sc When running python unit tests, 71 functions across the codebase are shape checked. An agent found 334 eligible functions inside gigl/ which means our coverage is about 21%

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 20, 2026
@jchmura-sc

Copy link
Copy Markdown
Collaborator Author

/e2e_test

@github-actions

Copy link
Copy Markdown
Contributor

GiGL Automation

@ 20:55:12UTC : 🔄 E2E Test started.

@jchmura-sc
jchmura-sc added this pull request to the merge queue Aug 20, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 20, 2026
@jchmura-sc
jchmura-sc added this pull request to the merge queue Aug 20, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 20, 2026
@jchmura-sc
jchmura-sc added this pull request to the merge queue Aug 20, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 21, 2026
@jchmura-sc
jchmura-sc enabled auto-merge August 21, 2026 01:37
@jchmura-sc
jchmura-sc added this pull request to the merge queue Aug 21, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 21, 2026
@jchmura-sc
jchmura-sc added this pull request to the merge queue Aug 21, 2026
Any commits made after this event will not be merged.
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