Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
test(compile): guard the duck-shaping checks on a torch without the config
thread3dd6282036f567
diff --git a/tests/test_backends.py b/tests/test_backends.pyindex b76442f6..aa53dcba 100644--- a/tests/test_backends.py+++ b/tests/test_backends.py@@ -177,13 +177,19 @@ check_true("auto fallback/names resolved compile, not auto",len(w) == 1 and "backend 'compile'" in str(w[0].message) and "backend 'auto'" not in str(w[0].message))cuda_agent = fake_agent("cuda")-cfg = torch.fx.experimental._config-prior_duck = cfg.use_duck_shape+# `torch.fx.experimental._config` only exists where symbolic shapes do; `laya._compile`+# degrades to a no-op without it, so the duck-shape assertions are made only where there+# is a setting to observe.+from laya._compile import _fx_config # noqa: E402++cfg = _fx_config()+prior_duck = cfg.use_duck_shape if cfg is not None else Nonedef compile_stub(fn, **kwargs):check("compile/reuses dynamic helper", kwargs, {"dynamic": True, "mode": "reduce-overhead"})def call(*args):- check("compile/independent dimensions during forward", cfg.use_duck_shape, False)+ if cfg is not None:+ check("compile/independent dimensions during forward", cfg.use_duck_shape, False)return fn(*args)return call@@ -191,7 +197,8 @@ with patch.object(torch, "compile", side_effect=compile_stub):be = backends.install(cuda_agent, "compile", strict=True, warmup=False)actual = cuda_agent.model(**b)check_true("compile/padding sliced away", torch.equal(actual[0], ref))- check("compile/duck shape restored after forward", cfg.use_duck_shape, prior_duck)+ if cfg is not None:+ check("compile/duck shape restored after forward", cfg.use_duck_shape, prior_duck)be.uninstall()check_true("compile/uninstall restores stock", untouched(cuda_agent.model))with patch.object(torch, "compile", side_effect=compile_stub), \diff --git a/tests/test_compile.py b/tests/test_compile.pyindex 4e58c2fc..50fca31a 100644--- a/tests/test_compile.py+++ b/tests/test_compile.py@@ -11,14 +11,22 @@ import threadingfrom types import SimpleNamespaceimport torch+import pytestsys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))-from laya._compile import compile_model, independent_dims # noqa: E402+from laya._compile import compile_model, independent_dims, _fx_config # noqa: E402from laya.agent import Agent, _pad_cuda_compile_batch # noqa: E402from laya.common import DecisionModel # noqa: E402-fx_config = torch.fx.experimental._config+# `torch.fx.experimental._config` only exists where duck sizing does; `laya._compile` degrades+# to a no-op without it, so the tests that observe the setting skip rather than assert on a+# knob this torch does not have.+fx_config = _fx_config()+requires_fx_config = pytest.mark.skipif(+ fx_config is None,+ reason="the compile path (duck sizing, and transformers' CPU compile support) needs a "+ "newer torch; it falls back to eager here")# rows x tokens x markers; the first has rows == markers, which duck sizing would tie togetherSHAPES = [(4, 40, 4), (4, 57, 4), (3, 70, 4), (5, 33, 2), (2, 90, 3), (8, 130, 5), (6, 61, 6), (7, 45, 3)]@@ -80,11 +88,12 @@ def test_cuda_compile_padding_masks_only_the_new_tail():assert _pad_cuda_compile_batch(padded, 0) is padded+@requires_fx_configdef test_one_graph_across_shapes_and_same_outputs():torch._dynamo.reset()model = tiny_model()agent = compiled_agent(model)- before = fx_config.use_duck_shape+ before = fx_config.use_duck_shape if fx_config is not None else Nonestart = graphs()with torch.no_grad():for shape in SHAPES:@@ -96,9 +105,11 @@ def test_one_graph_across_shapes_and_same_outputs():# stock torch.compile(model) builds 4 graphs for these shapes (static, then automatic dynamic,# then two duck-sizing recompiles); dynamic=True with independent dimensions builds oneassert graphs() - start == 1, graphs() - start- assert fx_config.use_duck_shape is before+ if fx_config is not None:+ assert fx_config.use_duck_shape is before+@requires_fx_configdef test_warmup_builds_every_graph_before_the_first_request():torch._dynamo.reset()agent = compiled_agent(tiny_model())@@ -114,6 +125,7 @@ def test_warmup_builds_every_graph_before_the_first_request():assert graphs() - start == 2, graphs() - start+@requires_fx_configdef test_duck_shape_restored_after_errors_and_nesting():before = fx_config.use_duck_shapewith independent_dims():@@ -130,6 +142,7 @@ def test_duck_shape_restored_after_errors_and_nesting():assert fx_config.use_duck_shape is before+@requires_fx_configdef test_duck_shape_restored_across_threads():before = fx_config.use_duck_shapeinside, left, release = threading.Barrier(4), threading.Barrier(4), threading.Event()@@ -156,6 +169,7 @@ def test_duck_shape_restored_across_threads():assert fx_config.use_duck_shape is before+@requires_fx_configdef test_eager_agent_leaves_the_setting_alone():agent = Agent.__new__(Agent)agent.device = torch.device("cpu")@@ -232,6 +246,7 @@ def test_constructor_warms_only_the_active_compiled_path():cache_spy.assert_not_called()+@requires_fx_configdef test_missing_compiler_preserves_wrapper_and_warns_only_during_automatic_warmup():import jsonimport tempfile