Skip to content

misc small issues (n_trajectories -> batch_size, removed fill_value)#491

Open
josephdviviano wants to merge 3 commits intomasterfrom
claude/torchgfn-patch-JWxYv
Open

misc small issues (n_trajectories -> batch_size, removed fill_value)#491
josephdviviano wants to merge 3 commits intomasterfrom
claude/torchgfn-patch-JWxYv

Conversation

@josephdviviano
Copy link
Copy Markdown
Collaborator

  • I've read the .github/CONTRIBUTING.md file
  • My code follows the typing guidelines
  • I've added appropriate tests
  • I've run pre-commit hooks locally

Description

  • removed fill_value (defaults to 0 everywhere)
  • renamed n_trajectories to batch_size
  • improved documentation of DDP / MoG tutorials.

claude added 3 commits March 14, 2026 21:25
The fill_value parameter in get_trajectory_pfs, get_trajectory_pbs, and
get_trajectory_pfs_and_pbs was never used with a non-zero value anywhere
in the codebase. Hardcode it to 0.0 and remove the parameter to simplify
the API and prevent users from accidentally changing probability calculations.

Also removes a dead code optimization branch (fill_value != 0.0 check in
non-vectorized PF path) and the related TODO comment in get_transition_pbs.

Closes #455

https://claude.ai/code/session_01NEvxmZxmjXDdSKghSeEcN8
The property n_trajectories on the Trajectories container is actually
the batch size of the container. Rename it to batch_size for clarity
and consistency with the rest of the codebase (e.g. RolloutContext
already uses batch_size).

This rename covers the property definition, all property accesses,
local variables derived from it, assertions, and shape descriptions
in docstrings/comments across 11 files. Tutorial CLI arguments that
use n_trajectories for "total trajectories to train" are intentionally
left unchanged as they represent a different concept.

Closes #456

https://claude.ai/code/session_01NEvxmZxmjXDdSKghSeEcN8
Add detailed docstrings and inline comments to train_hypergrid_ddp.py and
train_hypergrid_mog.py to improve readability for new users. Key additions:
- Function docstrings with Args/Returns for all setup functions and main()
- Inline comments explaining DDP buffer rank assignment (round-robin modulo)
- Comments for WandB two-stage string broadcast pattern
- On-policy detection logic explanation
- Profiler schedule phase descriptions (wait/warmup/active)
- Gradient all-reduce explanation in DDP sync blocks
- MoG module docstring with mixture reward shaping math
- f_theta classifier training and synchronization comments

https://claude.ai/code/session_01NEvxmZxmjXDdSKghSeEcN8
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 standardizes trajectory dimension naming to batch_size across core containers/utilities and tutorial scripts, and improves the readability of the DDP/MoG example scripts through expanded docstrings/comments.

Changes:

  • Replace n_trajectories terminology with batch_size across Trajectories, samplers, GFlowNet scoring, and related tutorial/test code.
  • Remove the fill_value parameter from trajectory PF/PB probability helpers and propagate the updated API through call sites/tests.
  • Expand documentation/comments in HyperGrid DDP and MoG training examples to better explain control flow and synchronization.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tutorials/examples/train_hypergrid_mog.py Adds detailed module/function docs and clarifies on-policy detection + mixture reward shaping comments.
tutorials/examples/train_hypergrid_gafn.py Updates shape/docs and indexing to use trajectories.batch_size.
tutorials/examples/train_hypergrid_ddp.py Expands docstrings/comments describing setup, buffer-rank mapping, WandB group broadcast, profiler schedule, and grad sync.
tutorials/examples/train_box.py Updates comment to reflect batch_size naming.
testing/test_probability_calculations.py Updates assertions for batch_size and removes now-unsupported fill_value usage in modern calls.
src/gfn/utils/prob_calculations.py Removes fill_value argument from PF/PB helpers; renames internal shape variables to batch_size.
src/gfn/states.py Updates documentation to use batch_size terminology.
src/gfn/samplers.py Renames n_trajectories local variables to batch_size in sampling and local-search logic.
src/gfn/gym/bitSequence.py Updates naming to batch_size in generated-trajectory helper.
src/gfn/gflownet/sub_trajectory_balance.py Updates docstrings and tensor shapes to use batch_size.
src/gfn/gflownet/base.py Updates docs/asserts to batch_size and removes fill_value from get_pfs_and_pbs.
src/gfn/containers/trajectories.py Renames public property to batch_size and updates related logic/docs.
src/gfn/actions.py Updates docs to use batch_size terminology.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

The terminating states.
"""
return self.states[self.terminating_idx - 1, torch.arange(self.n_trajectories)]
return self.states[self.terminating_idx - 1, torch.arange(self.batch_size)]
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 76.92308% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.40%. Comparing base (3d1acb2) to head (eece132).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/gfn/gflownet/base.py 0.00% 2 Missing ⚠️
src/gfn/utils/prob_calculations.py 33.33% 2 Missing ⚠️
src/gfn/containers/trajectories.py 92.85% 1 Missing ⚠️
src/gfn/samplers.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #491      +/-   ##
==========================================
+ Coverage   73.37%   73.40%   +0.03%     
==========================================
  Files          51       51              
  Lines        7533     7529       -4     
  Branches      904      903       -1     
==========================================
  Hits         5527     5527              
+ Misses       1674     1671       -3     
+ Partials      332      331       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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