Conversation
…forward-pass tests - Add tests/conftest.py with shared fixtures: shapes, rng, sample_data, and one fixture per CFM matcher class - Add tests/test_utils.py covering eight_normal_sample, sample_moons, sample_8gaussians, and torch_wrapper - Add tests/test_integration.py with a @pytest.mark.slow end-to-end CFM training smoke test (asserts loss decreases) - Expand tests/test_models.py with forward-pass tests for MLP (time-varying/non-time-varying/out_dim) and GradModel (instantiation, forward, gradient correctness) - Fix typo 'classers' -> 'classes' in test_conditional_flow_matcher.py and test_optimal_transport.py docstrings
Contributor
Reviewer's GuideExpands the TorchCFM test suite with shared fixtures, utility function coverage, model forward-pass tests, and an end-to-end CFM training smoke test, plus minor docstring typo fixes. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
tests/conftest.py, consider removing thefrom torchcfm.conditional_flow_matching import *star import and explicitly importing only the matcher classes that are actually used to keep the test namespace minimal and avoid accidental name clashes. - The gradient correctness test in
test_grad_model_is_gradientusescreate_graph=Trueeven though the resulting graph is not reused; you can drop this flag to reduce autograd overhead while keeping the test behavior identical.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `tests/conftest.py`, consider removing the `from torchcfm.conditional_flow_matching import *` star import and explicitly importing only the matcher classes that are actually used to keep the test namespace minimal and avoid accidental name clashes.
- The gradient correctness test in `test_grad_model_is_gradient` uses `create_graph=True` even though the resulting graph is not reused; you can drop this flag to reduce autograd overhead while keeping the test behavior identical.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expands the test suite with shared fixtures, utility tests, an integration smoke test, and model forward-pass tests.
Changes
shapes(parametrized over[(2,3),(5,2),(10,1),(3,3,2)]),rng(torch.Generatorseed 42),sample_data(x0/x1 standard normal), and one fixture per matcher classeight_normal_sample,sample_moons,sample_8gaussians, andtorch_wrapper.plot_trajectoriesis@pytest.mark.skip(needs matplotlib display)@pytest.mark.slowend-to-end CFM training smoke test — 256 moons samples,MLP(dim=2, w=32, time_varying=True),ConditionalFlowMatcher(sigma=0.0), 100 Adam steps at lr=1e-2; assertsfinal_loss < initial_loss(expanded 13 → 78 lines): added forward-pass tests forMLP(time-varying / non-time-varying / out_dim) andGradModel` (instantiation, forward, gradient correctness via autograd comparison)classers→classesintest_conditional_flow_matcher.pyandtest_optimal_transport.pydocstringsMotivation
Previously
tests/had only 4 files, noconftest.py, no integration tests, no tests forutils.py, andtest_models.pyonly instantiated models without testing the forward pass. This fills those gaps.Validation
All new tests pass against a merged branch containing all 4 PRs in this batch:
Coverage increased from 30% → 47% total. Core modules at 100%.
Notes
torchcfm/utils.pyfunction signatures differed from initial expectations (eight_normal_sample(n, dim, scale=1, var=1)requiresdim;sample_moons(n)returns numpy;torch_wrapperis a class). Tests were written against the actual source.--doctest-modulesflag inpyproject.tomlis a harmless no-op (no>>>doctests exist intorchcfm/).Summary by Sourcery
Expand the test suite with shared fixtures, utility function coverage, model forward-pass checks, and an end-to-end CFM training smoke test.
Tests: