Back to all reviewers

Actionable error messages

pytorch/pytorch
Based on 2 comments
C++

When writing error messages in PyTorch code, include not only what went wrong but also clear guidance on how to fix the issue. This helps users quickly understand and resolve problems without digging through documentation.

Pytorch C++

Reviewer Prompt

When writing error messages in PyTorch code, include not only what went wrong but also clear guidance on how to fix the issue. This helps users quickly understand and resolve problems without digging through documentation.

Example from tensor device operations:

// Poor error message:
TORCH_CHECK(false, "Cannot move tensor between devices");

// Better error message with remediation:
TORCH_CHECK(
  !force_move,
  "cannot move tensor from ", 
  data.device(),
  " to ", 
  device,
  " without copying. Set copy=True is needed.");

This practice is especially important for operations that have non-obvious requirements or constraints, such as tensor movement between devices, shape transformations, or operations with specific dtype requirements. By providing actionable guidance directly in error messages, you improve the developer experience and reduce support burden.

2
Comments Analyzed
C++
Primary Language
Pytorch
Category

Source Discussions