Skip to content

test(inference): run the real-inference test on CPU and move it out of tests/inference/tests - #144

Open
ddaihao2022 wants to merge 1 commit into
LLMSQL:mainfrom
ddaihao2022:fix-109-cpu-integration-test
Open

ddaihao2022 wants to merge 1 commit into
LLMSQL:mainfrom
ddaihao2022:fix-109-cpu-integration-test

Conversation

@ddaihao2022

Copy link
Copy Markdown
Contributor

Closes #109

Problem

test_real_inference_limit is meant to exercise the transformers backend on CPU, but it never passed a device_map, so inference_transformers fell back to its default "auto". On a machine with a visible CUDA GPU the model is offloaded to the GPU and Triton then tries to JIT-compile a helper kernel, which fails when the Python development headers are missing (Python.h: No such file or directory).

The same test also lived in tests/inference/tests/integration/, a needless extra level of nesting.

What changed

  • tests/inference/tests/integration/test_inference_transformers_real_limit.py -> tests/integration/test_inference_transformers_real_limit.py (pure move; nothing references the old path, and CI invokes bare pytest).
  • Pin the run to CPU explicitly: device_map="cpu" and an autouse fixture that sets CUDA_VISIBLE_DEVICES="", so even an indirectly-derived placement cannot pick the GPU.
  • Add dtype="float32". Once execution is pinned to CPU there is no reason to keep the default float16: fp16 CPU kernels are slow and are the likeliest source of "unimplemented on CPU" errors. _resolve_dtype accepts the string and resolves it to torch.float32.
  • Add the already-registered @pytest.mark.slow marker next to @pytest.mark.integration.
  • Add the missing trailing newline so ruff no longer complains.

Only this one test file is touched — nothing under llmsql/.

Verification

  • ruff check tests/integration and ruff format --check tests/integration: clean.
  • Confirm by AST inspection that inference_transformers really accepts device_map / dtype as keyword-only arguments, and that _resolve_dtype("float32") resolves to a torch.dtype.
  • Whole-file move only; no production code changed.
  • Actually run tests/integration end to end — not possible on my machine: torch and transformers are not installed (multi-GB wheels, no GPU), so this file and the four other transformers tests cannot even be collected locally. The fix takes effect only on a machine with a visible GPU / the transformers extra, i.e. CI.

No-regression check

Ran the CPU-runnable subset before and after the change:

PYTHONPATH=. pytest tests/ --ignore=tests/inference --ignore=tests/integration

Both runs give exactly the same result — 7 failed, 157 passed, 2 skipped. The 7 failures are pre-existing on main and all come from the missing transformers/torch install (6 of them) plus one unrelated tempfile assertion in tests/utils/test_inference_utils.py. My change does not move that number.

Happy to adjust if you'd rather keep fp16 and mask CUDA only — I can drop the dtype argument.

…f tests/inference/tests

Closes LLMSQL#109

- 这条集成测试没有指定 device_map,用的是 inference_transformers 的默认值
  "auto"。在有可见 CUDA GPU 的机器上模型会被搬到显卡上,Triton 随后 JIT
  编译辅助 kernel,在缺 Python 开发头文件的环境里编不过
  (Python.h: No such file or directory),一条本该纯 CPU 的测试直接失败。
  现在显式传 device_map="cpu",并用 autouse fixture 把 CUDA_VISIBLE_DEVICES
  置空兜底。
- CPU 上跑 fp16 既慢又容易撞到 PyTorch 未实现的 fp16 CPU 算子,这里显式用
  dtype="float32"(_resolve_dtype 接受字符串,解析成 torch.float32)。
- 目录从 tests/inference/tests/integration/ 挪到 tests/integration/,
  去掉多余的嵌套;仓库里没有任何地方按旧路径引用它,CI 用的是裸 pytest。
- 补上 @pytest.mark.slow(pyproject 里已注册),以及文件末尾缺失的换行。

只动这一个测试文件,未触碰 llmsql/ 下的产品代码。
@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tests] Real-inference CPU test fails when a GPU is visible

1 participant