Skip to content

fix corss_entropy rules#679

Open
feixi139 wants to merge 1 commit into
PFCCLab:mainfrom
feixi139:fix_cross_entropy
Open

fix corss_entropy rules#679
feixi139 wants to merge 1 commit into
PFCCLab:mainfrom
feixi139:fix_cross_entropy

Conversation

@feixi139

@feixi139 feixi139 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Paddle.cross_entropy,有axis参数,其处理方式为:

  1. 沿 axis 那一维做 softmax;
  2. 把除 axis 以外的所有维全部压平成一个大 batch 维,得到 [N_flat, C],其中 N_flat = 所有非 axis 维的乘积;
  3. 对这 N_flat 个"位置",每个独立地取 -log_softmax[label]。

torch.cross_entropy,没有aixs参数,靠张量维数来选:

  • 输入 2 维 [N, C] → 走 2D kernel
  • 输入 ≥3 维 [N, C, d...] → 走 spatial kernel(把第 1 维当类别、后面当空间维)

原本PaddleAPITest内逻辑:
image
修改后:
image

@paddle-bot

paddle-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

Thanks for your contribution!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant