Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
test: keep the nvfp4 loader forwards off torch's CPU bf16 GEMM
Lincoln Stein2aa5a87ad985
diff --git a/tests/AGENTS.md b/tests/AGENTS.mdindex f2dc37b183..2ea50aedf6 100644--- a/tests/AGENTS.md+++ b/tests/AGENTS.md@@ -5,6 +5,7 @@- Name tests by outcome; cover meaningful edge/failure cases and survive behavior-preserving refactors. Prefer real temporary SQLite/filesystem/tensor operations. Mock external services, expensive models, or unavailable hardware without mocking the transaction, authorization, concurrency, or numerical behavior under test.- Isolate paths, databases, accounts, clocks, seeds, environment, and network behavior. Clean up subprocesses, listeners, patches, and resources; never use production model/database/output directories.- Cover affected rollback, revisions, cross-user isolation, retries, cancellation, bounds, and cleanup. IndexedDB, Web Locks, focus, and rendering belong in webv2 browser tests.-- Use root pytest commands. CI runs xdist workers per vCPU; `--dist loadfile` in `addopts` keeps each file on one worker, with arbitrary file assignment/order. Each file must establish its own process-global state (e.g. JWT secret) and pass alone; verify new files independently.+- Use root pytest commands. CI runs xdist workers per vCPU, except windows, which runs fewer; `--dist loadfile` in `addopts` keeps each file on one worker, with arbitrary file assignment/order. Each file must establish its own process-global state (e.g. JWT secret) and pass alone; verify new files independently.- Default tests assert behavior, not throughput/latency under runner contention. Generous hang ceilings are acceptable; CPU time tolerates contention better than wall time. Hardware/quiet-machine measurements require `slow`, excluded by default and CI. On development machines, use `-m slow` for that lane or `-m ""` for everything.- State hardware prerequisites and skipped/unavailable devices. CPU/mocked passes do not establish CUDA/ROCm/MPS/XPU behavior.+- Do not run a CPU bf16 matmul unless low precision is the behavior under test: torch's CPU bf16 GEMM faults with an illegal instruction (`0xc000001d`) on part of the hosted windows fleet, which aborts the worker and fails the job. Run the forward at float32 and assert the width separately, as the nvfp4 loader tests do; skip on win32 only when bf16 itself is the subject.diff --git a/tests/backend/model_manager/load/test_krea2_nvfp4_loader.py b/tests/backend/model_manager/load/test_krea2_nvfp4_loader.pyindex 302846702d..49298792c0 100644--- a/tests/backend/model_manager/load/test_krea2_nvfp4_loader.py+++ b/tests/backend/model_manager/load/test_krea2_nvfp4_loader.py@@ -144,8 +144,11 @@ def test_header_named_nvfp4_layers_are_packed_under_their_diffusers_paths(loadedassert module.weight.dtype is torch.uint8, path# Installed after the cast, which would otherwise round the global scale to the compute dtype.assert module.weight_scale_2.dtype is torch.float32, path- x = torch.randn(3, module.in_features, dtype=COMPUTE_DTYPE)- torch.testing.assert_close(module(x), x @ loaded.expected[path].to(COMPUTE_DTYPE).T)+ # A float32 activation, not the compute dtype: torch 2.7's CPU bf16 GEMM faults with an illegal+ # instruction on part of GitHub's windows runner fleet. These values are exact in either width, and the+ # decode's own dtype threading is pinned by tests/backend/quantization/test_nvfp4.py.+ x = torch.randn(3, module.in_features, dtype=torch.float32)+ torch.testing.assert_close(module(x), x @ loaded.expected[path].T)def test_the_neighbouring_layers_load_as_their_own_branch_leaves_them(loaded) -> None:@@ -153,6 +156,8 @@ def test_the_neighbouring_layers_load_as_their_own_branch_leaves_them(loaded) ->time_embed = model.time_embed.linear_1assert type(time_embed) is torch.nn.Linear+ # Separately from the values: `torch.equal` promotes, so it alone would accept any width.+ assert time_embed.weight.dtype is COMPUTE_DTYPEassert torch.equal(time_embed.weight, loaded.expected["time_embed.linear_1"].to(COMPUTE_DTYPE))assert torch.equal(time_embed.bias, loaded.dense["tmlp.0.bias"].to(COMPUTE_DTYPE))assert torch.equal(model.img_in.weight, loaded.dense["first.weight"].to(COMPUTE_DTYPE))diff --git a/tests/backend/model_manager/load/test_mistral_encoder_checkpoint_loader.py b/tests/backend/model_manager/load/test_mistral_encoder_checkpoint_loader.pyindex e51492bde7..7cd8662fbd 100644--- a/tests/backend/model_manager/load/test_mistral_encoder_checkpoint_loader.py+++ b/tests/backend/model_manager/load/test_mistral_encoder_checkpoint_loader.py@@ -160,8 +160,10 @@ def test_an_nvfp4_mixed_checkpoint_keeps_its_nvfp4_layers_packed_under_either_fpassert module.weight.dtype is torch.uint8, path# Installed after the cast, which would otherwise round the global scale to the compute dtype.assert module.weight_scale_2.dtype is torch.float32, path- x = torch.randn(3, module.in_features, dtype=COMPUTE_DTYPE)- torch.testing.assert_close(module(x), x @ weight.to(COMPUTE_DTYPE).T)+ # A float32 activation, not the compute dtype: torch 2.7's CPU bf16 GEMM faults with an illegal+ # instruction on part of GitHub's windows runner fleet. These values are exact in either width.+ x = torch.randn(3, module.in_features, dtype=torch.float32)+ torch.testing.assert_close(module(x), x @ weight.T)for layer, weight in fp8_dequantized.items():v_proj = model.layers[layer].self_attn.v_projif keep_fp8:diff --git a/tests/backend/model_manager/load/test_qwen_image_nvfp4_loader.py b/tests/backend/model_manager/load/test_qwen_image_nvfp4_loader.pyindex 83eccdd5ec..6c279b8205 100644--- a/tests/backend/model_manager/load/test_qwen_image_nvfp4_loader.py+++ b/tests/backend/model_manager/load/test_qwen_image_nvfp4_loader.py@@ -170,8 +170,11 @@ def test_the_transformer_keeps_nvfp4_packed_and_scaled_fp8_only_where_something_assert isinstance(module, NVFP4Linear), pathassert module.weight.dtype is torch.uint8, pathassert module.weight_scale_2.dtype is torch.float32, path- x = torch.randn(3, module.in_features, dtype=COMPUTE_DTYPE)- expected_out = torch.nn.functional.linear(x, weight.to(COMPUTE_DTYPE), biases[path].to(COMPUTE_DTYPE))+ # A float32 activation, not the compute dtype: torch 2.7's CPU bf16 GEMM faults with an illegal+ # instruction on part of GitHub's windows runner fleet. These values are exact in either width.+ x = torch.randn(3, module.in_features, dtype=torch.float32)+ # The bias keeps the width the load rounded it to; the forward upcasts it to the activation.+ expected_out = torch.nn.functional.linear(x, weight, biases[path].to(COMPUTE_DTYPE).float())torch.testing.assert_close(module(x), expected_out)fp8_layer = model.transformer_blocks[0].txt_mlp.net[2]if mode == "fold":@@ -187,8 +190,8 @@ def test_the_transformer_keeps_nvfp4_packed_and_scaled_fp8_only_where_something_# without the scale before CustomLinear could apply it.fp8_bias = fp8_layer.bias.detach().to(COMPUTE_DTYPE)apply_custom_layers_to_model(model)- x = torch.randn(3, 64, dtype=COMPUTE_DTYPE)- expected_fp8_out = torch.nn.functional.linear(x, (fp8_values * 0.5).to(COMPUTE_DTYPE), fp8_bias)+ x = torch.randn(3, 64, dtype=torch.float32)+ expected_fp8_out = torch.nn.functional.linear(x, (fp8_values * 0.5).to(COMPUTE_DTYPE).float(), fp8_bias.float())torch.testing.assert_close(model.transformer_blocks[0].txt_mlp.net[2](x), expected_fp8_out)# The reservation lands before the fold and before the split, whichever runs.assert log == ([True, True] if mode == "fold" else [True])@@ -276,9 +279,11 @@ def test_the_encoder_keeps_marker_named_nvfp4_layers_packed_under_their_transformodule = model.get_submodule(path)assert isinstance(module, NVFP4Linear), pathassert module.weight_scale_2.dtype is torch.float32, path- x = torch.randn(3, module.in_features, dtype=COMPUTE_DTYPE)- bias = q_bias.to(COMPUTE_DTYPE) if module.bias is not None else None- torch.testing.assert_close(module(x), torch.nn.functional.linear(x, weight.to(COMPUTE_DTYPE), bias))+ # A float32 activation, not the compute dtype: torch 2.7's CPU bf16 GEMM faults with an illegal+ # instruction on part of GitHub's windows runner fleet. These values are exact in either width.+ x = torch.randn(3, module.in_features, dtype=torch.float32)+ bias = q_bias.to(COMPUTE_DTYPE).float() if module.bias is not None else None+ torch.testing.assert_close(module(x), torch.nn.functional.linear(x, weight, bias))assert torch.equal(model.lm_head.weight, (fp8_values * 0.5).to(COMPUTE_DTYPE))assert torch.equal(model.model.visual.proj.weight, visual_weight.to(COMPUTE_DTYPE))assert log == [True]diff --git a/tests/backend/model_manager/load/test_z_image_loader_boundaries.py b/tests/backend/model_manager/load/test_z_image_loader_boundaries.pyindex b5122dfadb..7f83938ad2 100644--- a/tests/backend/model_manager/load/test_z_image_loader_boundaries.py+++ b/tests/backend/model_manager/load/test_z_image_loader_boundaries.py@@ -331,7 +331,10 @@ def test_an_nvfp4_checkpoint_loads_packed_with_its_qkv_split_on_tile_rows(monkeymodel = run.load(config)bf16 = torch.bfloat16- x = torch.randn(3, 64, dtype=bf16)+ # A float32 activation, not the compute dtype: torch 2.7's CPU bf16 GEMM faults with an illegal instruction+ # on part of GitHub's windows runner fleet. These values are exact in either width, and the bias below is+ # still asserted at the width the load rounded it to.+ x = torch.randn(3, 64, dtype=torch.float32)attention = model.layers[0].attentionfor projection, signs, magnitude in ((attention.to_q, qkv[:128], 0.5),@@ -340,13 +343,16 @@ def test_an_nvfp4_checkpoint_loads_packed_with_its_qkv_split_on_tile_rows(monkey):assert isinstance(projection, NVFP4Linear)assert projection.weight.dtype is torch.uint8- expected = torch.where(signs, magnitude, -magnitude).to(bf16)+ expected = torch.where(signs, magnitude, -magnitude)assert torch.equal(projection(x), torch.nn.functional.linear(x, expected))adaln = model.layers[0].adaLN_modulation[0]assert isinstance(adaln, NVFP4Linear)- expected = torch.nn.functional.linear(x, torch.where(modulation, 0.5, -0.5).to(bf16), modulation_bias.to(bf16))+ assert adaln.bias.dtype is bf16+ expected = torch.nn.functional.linear(x, torch.where(modulation, 0.5, -0.5), modulation_bias.to(bf16).float())assert torch.equal(adaln(x), expected)assert type(model.t_embedder.mlp[0]) is torch.nn.Linear+ # Separately from the values: `torch.equal` promotes, so it alone would accept any width.+ assert model.t_embedder.mlp[0].weight.dtype is bf16assert torch.equal(model.t_embedder.mlp[0].weight, torch.where(timestep, 0.5, -0.5).to(bf16))assert torch.equal(model.all_x_embedder["2-1"].weight, embedder.to(bf16))diff --git a/tests/backend/quantization/test_nvfp4.py b/tests/backend/quantization/test_nvfp4.pyindex f71b3fa4a5..863ab4aaa3 100644--- a/tests/backend/quantization/test_nvfp4.py+++ b/tests/backend/quantization/test_nvfp4.py@@ -101,6 +101,28 @@ def test_a_real_checkpoint_slice_decodes_to_its_bf16_build(layer: str) -> None:assert torch.equal(module(x), torch.nn.functional.linear(x, decoded.view(128, 128)))[email protected]("dtype", [torch.bfloat16, torch.float16, torch.float32])+def test_the_decode_lands_in_the_dtype_it_was_asked_for(dtype: torch.dtype) -> None:+ """The per-forward decode has to honour the dtype it is handed, not one of its own.++ A decode that fixes its own width is invisible to a forward run at that same width, and it breaks two+ contracts at once: `F.linear` refuses an activation whose dtype the weight does not share, and the node's+ working-memory reservation was sized from the compute dtype by `dequant_transient_bytes`. Asserted on the+ decode rather than through a forward because `torch.equal` promotes, and because a bf16 CPU GEMM faults on+ part of the hosted windows runner fleet with an illegal instruction (0xc000001d) -- see the nvfp4 loader tests,+ which run their forward at float32 for that reason, and `test_int8_convrot_linear_bf16_path_tracks_fp32_reference`,+ which skips on win32 for it. Worth revisiting when the windows lock moves off torch 2.7.x.+ """+ torch.manual_seed(5)+ positive = torch.randint(0, 2, (128, 64), dtype=torch.bool)+ module = _packed_linear(_signed_layer("proj", positive), "proj")++ weight = module._dequantized_weight(torch.device("cpu"), dtype)++ assert weight.dtype is dtype+ assert torch.equal(weight, torch.where(positive, 0.5, -0.5).to(dtype))++def test_popped_layers_keep_their_tensors_as_stored_and_leave_the_rest_for_the_fp8_path() -> None:fp8_weight = torch.randn(32, 32).to(torch.float8_e4m3fn)fp8_scale = torch.tensor(0.5)