Skip to content

feat: align nll_loss with PyTorch Python API#810

Draft
voltjia wants to merge 1 commit into
masterfrom
feat/align-nll-loss-python-api
Draft

feat: align nll_loss with PyTorch Python API#810
voltjia wants to merge 1 commit into
masterfrom
feat/align-nll-loss-python-api

Conversation

@voltjia

@voltjia voltjia commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Expose one full nll_loss interface in PyTorch Python parameter order.
  • Retain only the previous integer-reduction interface as a [[deprecated]] compatibility overload.

Motivation

The previous public interface exposed the lower-level ATen reduction enum and placed reduction before ignore_index. PyTorch users instead see size_average, ignore_index, reduce, and a string reduction in that order. The earlier revision added convenience overloads for every trailing default; this revision keeps the API surface minimal.

No standalone issue is associated with this alignment follow-up.

Type of Change

  • feat - new feature / new operator / new platform
  • fix - bug fix
  • perf - performance improvement (no behavioral change)
  • refactor - code restructuring without behavior change
  • test - adding or fixing tests only
  • docs - documentation only
  • build / ci - build system or CI configuration
  • chore - tooling, formatting, or other non-code changes
  • Breaking change

Platforms Affected

  • CPU (WITH_CPU)
  • NVIDIA (WITH_NVIDIA)
  • Iluvatar (WITH_ILUVATAR)
  • MetaX (WITH_METAX)
  • Cambricon (WITH_CAMBRICON)
  • Moore (WITH_MOORE)
  • Ascend (WITH_ASCEND)
  • PyTorch C++ bindings (WITH_TORCH)
  • Build system / CMake / CI
  • Python bindings / user-facing API

Smoke Test Result

Host: ssh nvidia
Image: accelerator-dev/nvidia:latest
PyTorch: 2.10.0a0+b4e4ee8

cmake ... -DWITH_CPU=ON -DWITH_NVIDIA=ON -DWITH_TORCH=ON \
  -DINFINI_OPS_OPS=nll_loss -DINFINI_OPS_TORCH_OPS=nll_loss
cmake --build build-nvidia --target ops -j 16
Build passed; codegen emitted 1 ATen implementation overload.

python -m pytest tests/test_generate_wrappers.py -q
13 passed

python -m pytest tests/test_nll_loss.py --devices cpu nvidia -q
48 passed

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
CPU Yes targeted build passed Included in 48 targeted cases
NVIDIA Yes targeted build passed Included in 48 targeted cases
Iluvatar No N/A - not affected N/A - not affected
MetaX No N/A - not affected N/A - not affected
Cambricon No N/A - not affected N/A - not affected
Moore No N/A - not affected N/A - not affected
Ascend No N/A - not affected N/A - not affected

Benchmark / Performance Impact

N/A. Reduction argument translation occurs during operator construction; the ATen execution path is unchanged.

Notes for Reviewers

API alignment

Interface Signature Alignment basis
InfiniOps primary nll_loss(input, target, weight, size_average, ignore_index, reduce, reduction, out) PyTorch names and Python order; explicit out remains last per CONTRIBUTING.md.
PyTorch public API F.nll_loss(input, target, weight=None, size_average=None, ignore_index=-100, reduce=None, reduction="mean") Pinned PyTorch source
Deprecated compatibility nll_loss(input, target, weight, reduction, ignore_index, out) Preserves the pre-alignment integer-reduction interface for migration.
  • C++ callers spell PyTorch defaults explicitly; no prefix/default convenience overloads are added.
  • size_average and reduce retain PyTorch's legacy override behavior when either is provided.
  • Ruff 0.15.22 and clang-format 21.1.8 checks passed.

@voltjia
voltjia changed the base branch from master to fix/pin-ruff-version July 24, 2026 07:53
@voltjia
voltjia force-pushed the feat/align-nll-loss-python-api branch from 08f7b04 to 214dc66 Compare July 24, 2026 08:02
Base automatically changed from fix/pin-ruff-version to master July 24, 2026 08:13
@voltjia
voltjia force-pushed the feat/align-nll-loss-python-api branch from 214dc66 to 9ed62f4 Compare July 24, 2026 08:27
@voltjia
voltjia force-pushed the feat/align-nll-loss-python-api branch from 9ed62f4 to d10fc8e Compare July 24, 2026 11:07
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