Skip to content

Metal Backend Support#40

Open
atticus-lv wants to merge 3 commits into
nv-tlabs:mainfrom
atticus-lv:main
Open

Metal Backend Support#40
atticus-lv wants to merge 3 commits into
nv-tlabs:mainfrom
atticus-lv:main

Conversation

@atticus-lv

@atticus-lv atticus-lv commented Jun 18, 2026

Copy link
Copy Markdown

ref #3 , this pr also modify the python part for device check
A blender addon repo for testing

2026-06-17.17-27-25.mp4

Add device-aware backend selection so Kimodo runs on Apple Silicon (MPS)
in addition to CUDA/CPU. Ported from tdw46's kimodo-metal-mps-support fork
(MPS portions of commit d0c7736 only; the Beyond Motion / f2llm encoder
swap and unrelated docs/benchmark edits are intentionally excluded).

- device_utils: resolve_torch_device (auto -> cuda > mps > cpu, with graceful
  fallback) and preferred_text_encoder_dtype (float16 on MPS, bfloat16
  otherwise, override-able via TEXT_ENCODER_DTYPE)
- kimodo_model: coerce stray fp64 buffers/params to fp32 on MPS (MPS cannot
  materialize float64) and align text features to the denoiser dtype
- skeleton/base: MPS-safe .to() that keeps fp64 -> fp32
- llm2vec: resolve device via device_utils; skip the CUDA multiprocessing
  branch for non-CUDA devices
- load_model: device-aware text-encoder dtype while preserving the existing
  text_encoder_fp32 override precedence (default encoder left as llm2vec)
- generate.py: add --device (auto/cpu/cuda/cuda:0/mps); demo app auto-resolves
- model: export AutoEmbeddingEncoder
The motion_correction C++ extension assumed an x86 + GCC toolchain and
could not build on Apple Silicon (or under clang generally):
- CMakeLists passed x86-only -msse4.1/-mavx, which clang rejects on arm64
- Compiler.h never defined FORCE_INLINE for clang (only MSVC/GCC)
- the Vector/SIMD math core is SSE-intrinsic only, with no NEON path

Guard the SIMD compile flags by target architecture, add the clang branch
for FORCE_INLINE, and have setup.py auto-skip the (optional) native
extension on non-x86 targets, where kimodo falls back to the pure-Python
postprocessing path. Set FORCE_MOTION_CORRECTION_BUILD=1 to override.
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.

1 participant