Add CPU-first inference with automatic SDPA fallback#85
Open
Lakshya717 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes LingBot-Map run on CPU-first setups without FlashInfer, so inference works on machines with no capable GPU or missing CUDA wheels.
Why
The repo assumed CUDA + FlashInfer by default. On this dev machine (i5-13420H, 13 GB RAM, RTX 2050 4 GB), FlashInfer was unavailable and the ~4.4 GB checkpoint cannot fit in VRAM. The goal was reliability over speed — run anywhere, GPU optional.
What changed
lingbot_map/utils/device.py— device/dtype resolution, autocast helper, FlashInfer probe, SDPA vs FlashInfer backend selectiondemo.py—--device(cpudefault), auto SDPA when FlashInfer missing, device-aware autocast, images stay on CPU,--offload_to_cpudefault onaggregator/stream.py— soft FlashInfer → SDPA fallback at build time (no crash)gct_base.py— device-aware autocast in prediction headsgeometry.py— replace hard.cuda()with.to(device)FlashInfer remains an optional CUDA fast path; SDPA is the portable default.
Status
Successful — CPU inference path works without FlashInfer. Verified locally: FlashInfer import fails → SDPA selected;
--device autocorrectly falls back to CPU on low VRAM (~3.2 GiB free).Local results (this machine)
demo.py --device cpu(SDPA, no FlashInfer)Follow-up (not in this PR)
Further refinement is needed for hybrid / partial offload — e.g. weights on CPU with selective GPU compute when VRAM allows, or smarter auto-switching between CPU and CUDA within a single run. Current scope is CPU-only or explicit CUDA, not layered weight offload.