Skip to content

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

Open
Pablosinyores wants to merge 1 commit into
ml-explore:mainfrom
Pablosinyores:fix/bce-docstring-arg-order
Open

Fix binary_cross_entropy docstring argument order (weights before with_logits)#3807
Pablosinyores wants to merge 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.

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.

1 participant