def test_correctness_use_adaptive_pooling(): if mge.is_cuda_available(): model_name = "mnist_model_with_test.mge" else: model_name = "mnist_model_with_test_cpu.mge" model_path = os.path.join(os.path.dirname(__file__), model_name) set_execution_strategy("HEURISTIC_REPRODUCIBLE") run_train(model_path, False, False, max_err=1e-5, use_adaptive_pooling=True) run_train(model_path, True, False, max_err=1e-5, use_adaptive_pooling=True) run_train(model_path, True, True, max_err=1e-5, use_adaptive_pooling=True) # sublinear config = SublinearMemoryConfig(genetic_nr_iter=10) run_train( model_path, True, True, sublinear_memory_config=config, max_err=1e-5, use_adaptive_pooling=True, ) run_eval(model_path, False, max_err=1e-7, use_adaptive_pooling=True) run_eval(model_path, True, max_err=1e-7, use_adaptive_pooling=True)
def test_matmul(execution_strategy): @trace(symbolic=True, capture_as_const=True) def fwd(data1, data2): return F.matmul(data1, data2) old = get_execution_strategy() set_execution_strategy(execution_strategy) max_err = None if execution_strategy == "PROFILE_REPRODUCIBLE": max_err = 1e-5 data1 = Tensor(np.random.random((32, 64))) data2 = Tensor(np.random.random((64, 16))) result = fwd(data1, data2) check_pygraph_dump(fwd, [data1, data2], [result], max_err=max_err) set_execution_strategy(old)
def reproducible(): old = get_execution_strategy() set_execution_strategy("HEURISTIC_REPRODUCIBLE") yield set_execution_strategy(old)
def test_dp_correctness(): model_name = "mnist_model_with_test.mge" model_path = os.path.join(os.path.dirname(__file__), model_name) set_execution_strategy("HEURISTIC_REPRODUCIBLE") run_test(model_path, False, False, max_err=5e-5)