Skip to content

Fix binary_cross_entropy docstring argument order (weights before with_logits) - #3807

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
Pablosinyores:fix/bce-docstring-arg-order
Jul 7, 2026
Merged

Fix binary_cross_entropy docstring argument order (weights before with_logits)#3807
zcbenz merged 1 commit into
ml-explore:mainfrom
Pablosinyores:fix/bce-docstring-arg-order

Conversation

@Pablosinyores

Copy link
Copy Markdown
Contributor

The binary_cross_entropy Args block documents the parameters as inputs, targets, with_logits, weights, reduction, but the actual signature order is inputs, targets, weights, with_logits, reduction:

def binary_cross_entropy(
    inputs, targets,
    weights=None,          # 3rd positional
    with_logits=True,      # 4th positional
    reduction="mean",
)

A caller following the docstring order positionally, e.g. binary_cross_entropy(logits, targets, False) intending with_logits=False, instead binds weights=False. The weights is not None branch then does weights.shape on a bool and raises AttributeError: 'bool' object has no attribute 'shape'.

>>> nn.losses.binary_cross_entropy(mx.array([0.1,0.2]), mx.array([0,1]), False)
AttributeError: 'bool' object has no attribute 'shape'

This reorders the two Args entries so weights precedes with_logits, matching the signature. The sibling cross_entropy in the same file already documents weights in its correct signature position. Docstring-only change.

@zcbenz
zcbenz force-pushed the fix/bce-docstring-arg-order branch from c726406 to 7f09122 Compare July 6, 2026 23:41

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@zcbenz
zcbenz merged commit b837849 into ml-explore:main Jul 7, 2026
28 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