pytorch / pytorch/pytorch

[docs] Reference impl of `linear_cross_entropy` probably buggy for multi-dim inputs

Open
#196,749 4 comments 0 reactions 0 assignees View on GitHub
bot-triaged module: doc infra module: docs triaged
Dominant language
Python
Stars
103k
Forks
29.5k
PR merge metrics
PR metrics pending

Description

### 🐛 Describe the bug

Image

But for BTC input this should probably return a faulty result, as a `transpose(-1, 1)` (or `view(-1, num_classes)` is needed for F.cross_entropy to correctly detect the classes dimension

Also, the docs page even for a single function, as returned by search, includes a redundant `#...` (I would propose to drop these hash components in the url's for single-function html pages): https://docs.pytorch.org/docs/2.14/generated/torch.nn.functional.linear_cross_entropy.html#torch-nn-functional-linear-cross-entropy, cc @svekars @sekyondaMeta @AlannaBurke @ezyang @malfet

### Versions

N/A

Contributor guide

Open the contributing guide

Research direction

Start with the torch.nn.functional.linear_cross_entropy reference implementation and compare its handling of BTC-shaped inputs with F.cross_entropy's expected class dimension. Also inspect the generated single-function documentation URL for the redundant fragment. Done means the reference implementation handles multi-dimensional inputs correctly and the single-function page URL no longer includes the unnecessary hash component.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.