"""Prove torch_npu deterministic level 0/1/2 is synced to global config."""
import pytest
import torch_npu
import pypto
from pypto._utils import get_torch_npu_compute_determinism_level
from pypto.frontend.parser.entry import JitCallableWrapper
def _dummy_kernel(x):
return x
@pytest.fixture
def restore_determinism():
prev_level = int(torch_npu.npu._get_deterministic_level())
try:
yield
finally:
torch_npu.npu.set_deterministic_level(prev_level)
pypto.set_global_config("compute_determinism_level", 0)
def test_torch_npu_determinism_level_synced_to_global_config(restore_determinism):
"""torch_npu.set_deterministic_level -> set_global_config -> get_global_config."""
wrapper = JitCallableWrapper(None, _dummy_kernel, None)
for level in (0, 1, 2):
torch_npu.npu.set_deterministic_level(level)
assert get_torch_npu_compute_determinism_level() == level
wrapper._set_config_option()
assert pypto.get_global_config("compute_determinism_level") == level