code: def diagnose(
      rule: infra.Rule,
      level: infra.Level,
      message: Optional[str] = None,
      frames_to_skip: int = 2,
      **kwargs,
  ) -> TorchScriptOnnxExportDiagnostic:
      """Creates a diagnostic and record it in the global diagnostic context.
  
      This is a wrapper around `context.log` that uses the global diagnostic
      context.
      """
      # NOTE: Cannot use `@_beartype.beartype`. It somehow erases the cpp stack frame info.
      diagnostic = TorchScriptOnnxExportDiagnostic(
          rule, level, message, frames_to_skip=frames_to_skip, **kwargs
      )
      export_context().log(diagnostic)
      return diagnostic
  
imports: from __future__ import annotations
  import contextlib
  import gzip
  from collections.abc import Generator
  from typing import List, Optional
  import torch
  from torch.onnx._internal.diagnostics import infra
  from torch.onnx._internal.diagnostics.infra import formatter, sarif
  from torch.onnx._internal.diagnostics.infra.sarif import version
  from torch.utils import cpp_backtrace
label_desc: Use image node_id 3 for calling a global function with example usage: diagnose(rule, level, message, frames_to_skip) and returns: diagnostic