評價此頁

torch.onnx.verification#

創建於: 2025年3月18日 | 最後更新於: 2025年8月29日

一套用於驗證 ONNX 模型正確性的工具。

torch.onnx.verification.verify_onnx_program(onnx_program, args=None, kwargs=None, compare_intermediates=False)[source]#

透過將值與 ExportedProgram 中的預期值進行比較來驗證 ONNX 模型。

引數
  • onnx_program (_onnx_program.ONNXProgram) – 要驗證的 ONNX 程式。

  • args (tuple[Any, ...] | None) – 模型的輸入引數。

  • kwargs (dict[str, Any] | None) – 模型的關鍵字引數。

  • compare_intermediates (bool) – 是否驗證中間值。這將花費更長的時間,因此預設停用。

返回

包含每個值的驗證資訊的 VerificationInfo 物件。

返回型別

list[VerificationInfo]

class torch.onnx.verification.VerificationInfo(name, max_abs_diff, max_rel_diff, abs_diff_hist, rel_diff_hist, expected_dtype, actual_dtype)#

ONNX 程式中某個值的驗證資訊。

此類包含預期值與實際值之間的最大絕對差、最大相對差以及絕對差和相對差的直方圖。它還包括預期和實際資料型別。

直方圖表示為張量元組,其中第一個張量是直方圖計數,第二個張量是 bin 邊緣。

變數
  • name (str) – 值的名稱(輸出或中間值)。

  • max_abs_diff (float) – 預期值與實際值之間的最大絕對差。

  • max_rel_diff (float) – 預期值與實際值之間的最大相對差。

  • abs_diff_hist (tuple[torch.Tensor, torch.Tensor]) – 表示絕對差直方圖的張量元組。第一個張量是直方圖計數,第二個張量是 bin 邊緣。

  • rel_diff_hist (tuple[torch.Tensor, torch.Tensor]) – 表示相對差直方圖的張量元組。第一個張量是直方圖計數,第二個張量是 bin 邊緣。

  • expected_dtype (torch.dtype) – 預期值的資料型別。

  • actual_dtype (torch.dtype) – 實際值的型別。

asdict()[source]#

將 VerificationInfo 物件轉換為字典。

返回

VerificationInfo 物件的字典表示。

返回型別

dict[str, Any]

classmethod from_tensors(name, expected, actual)[source]#

從兩個張量建立 VerificationInfo 物件。

引數
返回

VerificationInfo 物件。

返回型別

VerificationInfo