Skip to content

fix(data): align dynamic_bucket kwarg between Python stub and pybind - #1510

Open
Ace3Z wants to merge 1 commit into
facebookresearch:mainfrom
Ace3Z:fix/dynamic-bucket-cost-fn-kwarg-mismatch
Open

fix(data): align dynamic_bucket kwarg between Python stub and pybind#1510
Ace3Z wants to merge 1 commit into
facebookresearch:mainfrom
Ace3Z:fix/dynamic-bucket-cost-fn-kwarg-mismatch

Conversation

@Ace3Z

@Ace3Z Ace3Z commented May 24, 2026

Copy link
Copy Markdown

Closes #1103.

Calling pipeline.dynamic_bucket(threshold=..., cost_fn=...) (the form the Python stub at src/fairseq2/data/data_pipeline.py:238 declares, and what Sphinx generates docs from) fails with TypeError: incompatible function arguments. The C++ pybind binding at native/python/src/fairseq2n/bindings/data/data_pipeline.cc:503 exposed the arg as py::arg("fn").

Renamed the pybind kwarg from fn to cost_fn so it matches the documented Python signature. cost_fn is also the C++ type alias name in native/src/fairseq2n/data/data_pipeline.h. Every internal caller (parquet table bucketing, existing tests) passes the cost function positionally, so this is source compatible.

Added a regression test in tests/unit/data/data_pipeline/test_dynamic_bucket.py that calls dynamic_bucket with cost_fn= as a kwarg. It fails on main with the exact TypeError from the issue and passes on this branch.

I didn't rebuild fairseq2n from source locally (CUDA toolchain isn't on this box), so CI will give it its real exercise across the matrix. The change itself is a one character substring swap in an existing py::arg() macro call, mechanically equivalent to its neighbors.

Side note: filter has the same bug (predicate in the stub vs py::arg("fn") in the binding, around line 516). Sending that as a separate PR.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 24, 2026
Ace3Z added a commit to Ace3Z/fairseq2 that referenced this pull request May 25, 2026
The Python stub `DataPipelineBuilder.filter` declared `predicate` while
the C++ pybind binding used `py::arg("fn")`, so calling
`pipeline.filter(predicate=...)` (the documented form) raised
`TypeError: incompatible function arguments`.

Same bug class as facebookresearch#1103 and the fix that landed in facebookresearch#1510 for
`dynamic_bucket`. Rename the pybind keyword from `fn` to `predicate`
so the runtime matches the documented Python signature. No internal
callsite uses the keyword form, so this is source-compatible for all
existing callers.

Add a regression test that exercises `filter(predicate=...)` and would
have caught the bug.

Follow-up to facebookresearch#1510.
The Python stub `DataPipelineBuilder.dynamic_bucket` declared `cost_fn`
while the C++ pybind binding used `py::arg("fn")`, so calling
`pipeline.dynamic_bucket(threshold=..., cost_fn=...)` (the documented
form) raised `TypeError: incompatible function arguments`.

Rename the pybind keyword from `fn` to `cost_fn` so the runtime matches
the documented Python signature and Sphinx-generated docs. No internal
callsite uses the keyword form, so this is source-compatible for all
existing callers.

Closes facebookresearch#1103
@Ace3Z
Ace3Z force-pushed the fix/dynamic-bucket-cost-fn-kwarg-mismatch branch from 2fcebfa to 66babe3 Compare May 25, 2026 10:16
Ace3Z added a commit to Ace3Z/fairseq2 that referenced this pull request May 25, 2026
fix(data): align filter() kwarg between Python stub and pybind

The Python stub `DataPipelineBuilder.filter` declared `predicate` while
the C++ pybind binding used `py::arg("fn")`, so calling
`pipeline.filter(predicate=...)` (the documented form) raised
`TypeError: incompatible function arguments`.

Same bug class as facebookresearch#1103 and the fix that landed in facebookresearch#1510 for
`dynamic_bucket`. Rename the pybind keyword from `fn` to `predicate`
so the runtime matches the documented Python signature. No internal
callsite uses the keyword form, so this is source-compatible for all
existing callers.

Follow-up to facebookresearch#1510.
Ace3Z added a commit to Ace3Z/fairseq2 that referenced this pull request May 25, 2026
The Python stub `DataPipelineBuilder.filter` declared `predicate` while
the C++ pybind binding used `py::arg("fn")`, so calling
`pipeline.filter(predicate=...)` (the documented form) raised
`TypeError: incompatible function arguments`.

Same bug class as facebookresearch#1103 and the fix that landed in facebookresearch#1510 for
`dynamic_bucket`. Rename the pybind keyword from `fn` to `predicate`
so the runtime matches the documented Python signature. No internal
callsite uses the keyword form, so this is source-compatible for all
existing callers.

Follow-up to facebookresearch#1510.
@Ace3Z

Ace3Z commented May 29, 2026

Copy link
Copy Markdown
Author

Friendly ping on this one. It's a small binding fix for #1103 with a regression test. @cirquit @cbalioglu whenever you have a moment, would appreciate a look.

@Ace3Z

Ace3Z commented May 29, 2026

Copy link
Copy Markdown
Author

Friendly ping. @cbalioglu, would you have a moment to look at this? Tiny pybind/stub alignment fix. Happy to address any feedback.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dynamic_bucket Python signature seems to be wrong

1 participant