frontend/pytorch: add aten::cross_entropy_loss translator and tests (fixes #29691, relates #28584)#32554
Conversation
|
This PR will be closed in a week because of 2 weeks of no activity. |
There was a problem hiding this comment.
Pull request overview
This PR implements the PyTorch cross_entropy_loss operation translator for OpenVINO, addressing issue #29691. The implementation follows PyTorch's specification where cross_entropy_loss = log_softmax + nll_loss, providing a complete translation from PyTorch operations to OpenVINO's operation set.
Changes:
- Implements cross_entropy_loss translator with support for three reduction modes (none, mean, sum), optional class weights, and spatial dimensions
- Registers the operation in the op_table with proper alphabetical ordering
- Adds comprehensive tests covering basic functionality, reduction modes, class weights, and spatial inputs
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/frontends/pytorch/src/op/cross_entropy_loss.cpp |
Core translator implementation with log_softmax + one-hot masking approach for NLL loss, supporting weights and all reduction modes |
src/frontends/pytorch/src/op_table.cpp |
Adds forward declaration and registration of the new translator in alphabetical order |
tests/layer_tests/pytorch_tests/test_cross_entropy_loss.py |
Test suite covering reduction modes (mean/sum/none), class weights, and spatial dimensions (2D and 4D inputs) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,153 @@ | |||
| // Copyright (C) 2018-2025 Intel Corporation | |||
There was a problem hiding this comment.
The copyright year should be 2018-2026 to be consistent with all other files in this directory.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
| @@ -0,0 +1,58 @@ | |||
| # Copyright (C) 2018-2025 Intel Corporation | |||
There was a problem hiding this comment.
The copyright year should be 2018-2026 to be consistent with all other test files in this directory.
|
This PR will be closed in a week because of 2 weeks of no activity. |
|
This PR was closed because it has been stalled for 2 week with no activity. |
1. Core Implementation
File:
src/frontends/pytorch/src/op/cross_entropy_loss.cppImplements the
translate_cross_entropy_lossfunction that converts PyTorch's cross_entropy_loss operation to OpenVINO operations. The implementation follows PyTorch's specification:Key features:
LogSoftmaxalong dimension 1 (class dimension)ReduceSumto select target class probabilities (NLL loss)Gather+Multiplynone(0): No reduction, returns per-sample lossmean(1): Mean of all losses (default)sum(2): Sum of all losses(N, C)and higher-dimensional inputs(N, C, d1, d2, ...)2. Operation Registration
File:
src/frontends/pytorch/src/op_table.cppOP_CONVERTER(translate_cross_entropy_loss);{"aten::cross_entropy_loss", op::translate_cross_entropy_loss},3. Tests
File:
tests/layer_tests/pytorch_tests/test_cross_entropy_loss.pyComprehensive test suite covering:
mean,sum,none)