class_docstr: Test cases for diagnostics emitted by the TorchScript ONNX export code.
class_docstr_tok: ["Test","cases","for","diagnostics","emitted","by","the","TorchScript","ONNX","export","code","."]
code: def _trigger_node_missing_onnx_shape_inference_warning_diagnostic_from_cpp(
      self,
  ) -> diagnostics.TorchScriptOnnxExportDiagnostic:
      class CustomAdd(torch.autograd.Function):
          @staticmethod
          def forward(ctx, x, y):
              return x + y
  
          @staticmethod
          def symbolic(g, x, y):
              return g.op("custom::CustomAdd", x, y)
  
      class M(torch.nn.Module):
          def forward(self, x):
              return CustomAdd.apply(x, x)
  
      # trigger warning for missing shape inference.
      rule = diagnostics.rules.node_missing_onnx_shape_inference
      torch.onnx.export(M(), torch.randn(3, 4), io.BytesIO())
  
      context = diagnostics.engine.contexts[-1]
      for diagnostic in context.diagnostics:
          if (
              diagnostic.rule == rule
              and diagnostic.level == diagnostics.levels.WARNING
          ):
              return typing.cast(
                  diagnostics.TorchScriptOnnxExportDiagnostic,
                  diagnostic,
              )
      raise AssertionError("No diagnostic found.")
  
imports: from __future__ import annotations
  import contextlib
  import dataclasses
  import io
  import logging
  import typing
  import unittest
  from typing import AbstractSet, Protocol, Tuple
  import torch
  from torch.onnx import errors
  from torch.onnx._internal import diagnostics
  from torch.onnx._internal.diagnostics import infra
  from torch.onnx._internal.diagnostics.infra import formatter, sarif
  from torch.onnx._internal.fx import diagnostics
  from torch.testing._internal import common_utils, logging_utils
label_desc: Use image node_id 2 for calling the TestTorchScriptOnnxDiagnostics obj's underlying member method code with example usage: obj._trigger_node_missing_onnx_shape_inference_warning_diagnostic_from_cpp() and returns: unknown, g, CustomAdd, typing