Skip to content

fix: make the package importable on Windows - #124

Open
JoaoZaokk wants to merge 1 commit into
nunchux-ai:mainfrom
JoaoZaokk:fix/windows-import
Open

fix: make the package importable on Windows#124
JoaoZaokk wants to merge 1 commit into
nunchux-ai:mainfrom
JoaoZaokk:fix/windows-import

Conversation

@JoaoZaokk

Copy link
Copy Markdown

Two unrelated defects, both of which stop import deepcompressor — and therefore deepcompressor.app.diffusion.ptq — before any work begins. Neither is Windows-specific by design; both are places where a platform default got assumed.

1. csrc/load.py builds with GCC flags

MSVC ignores them with D9002 warnings, which alone would be cosmetic. But CUDA ≥ 13 ships CCCL, and CCCL rejects MSVC's traditional preprocessor outright:

cccl/cuda/std/__cccl/preprocessor.h(23): fatal error C1189: #error:  MSVC/cl.exe with
traditional preprocessor is used. This may lead to unexpected compilation errors. Please
switch to the standard conforming preprocessor by passing `/Zc:preprocessor` to cl.exe.

This is not an opt-in build step a user can skip. The extension is JIT-built at import time along deepcompressor/data/__init__.pydtype.pycodebook.pycsrc/load.py, so the package does not import at all.

Fixed by passing /Zc:preprocessor to cl.exe directly (for pybind.cpp) and through nvcc via -Xcompiler (for quantize.cu), with MSVC equivalents substituted for the GCC flags. -fopenmp is part of that substitution on purpose: being silently ignored means the C++ side builds without OpenMP, which is quiet rather than harmless.

2. longbench/eval.py reads a UTF-8 file with the locale default

task2prompt.json contains CJK text. Without an explicit encoding the read uses cp1252 on Windows and raises at import:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1522: character maps to <undefined>

The sibling write on line 123 already passes encoding="utf-8"; only this read was missed.

Worth noting the blast radius: an LLM benchmark file that no diffusion workflow will ever read prevents app.diffusion.ptq from importing, because the diffusion PTQ entry point imports the LLM one.

Verification

Windows 11, Python 3.13, torch 2.13.0+cu130, CUDA 13.2, MSVC 14.44 (VS 2022 Build Tools), RTX 3090 (sm_86):

before after
JIT build fatal error C1189 compiles for sm_86
from deepcompressor.app.diffusion import ptq UnicodeDecodeError succeeds
python -m deepcompressor.app.diffusion.ptq --help never reached prints usage

Beyond importing, the pipeline was exercised end to end on SANA 1.6B: calibration collected 128/128 samples, and PTQ ran into the smoothing stage before being stopped for time on this hardware. So these two changes are what stood between the package and a working run on Windows, not the only thing that would have to work afterwards.

Linux behaviour is unchanged — both changes sit inside a sys.platform guard or add an argument that was already the implied default.

🤖 Generated with Claude Code

Two unrelated defects, both of which stop `import deepcompressor` (and so
`deepcompressor.app.diffusion.ptq`) before any work begins. Neither is
Windows-specific by design; both are places where a platform default was
assumed.

1. csrc/load.py builds with GCC flags.

   MSVC ignores them with D9002 warnings, which alone would be cosmetic. But
   CUDA >= 13 ships CCCL, and CCCL rejects MSVC's traditional preprocessor:

       cccl/cuda/std/__cccl/preprocessor.h(23): fatal error C1189: #error:
       MSVC/cl.exe with traditional preprocessor is used ... Please switch to
       the standard conforming preprocessor by passing `/Zc:preprocessor`

   The extension is JIT-built at import time from deepcompressor/data/__init__
   -> dtype -> codebook -> csrc/load, so this is not an opt-in build step that
   a user can skip: the package simply does not import.

   Fixed by passing /Zc:preprocessor to cl.exe directly (for pybind.cpp) and
   through nvcc via -Xcompiler (for quantize.cu), and substituting MSVC
   equivalents for the GCC flags. `-fopenmp` is included in that substitution
   deliberately -- being ignored means the C++ side is built without OpenMP,
   which is quiet rather than harmless.

2. longbench/eval.py reads a UTF-8 file with the locale default.

   task2prompt.json contains CJK text. Without an explicit encoding the read
   uses cp1252 on Windows and raises at import:

       UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position
       1522: character maps to <undefined>

   The write on line 123 already passes encoding="utf-8"; only this read was
   missed. Note the blast radius: an LLM benchmark file that no diffusion
   workflow will ever read prevents app.diffusion.ptq from importing, because
   the diffusion PTQ entry point pulls in the LLM one.

Verified on Windows 11, Python 3.13, torch 2.13.0+cu130, CUDA 13.2, MSVC
14.44 (VS 2022 Build Tools), RTX 3090 (sm_86):

  before  fatal error C1189 during the JIT build, then UnicodeDecodeError
  after   extension compiles for sm_86, `from deepcompressor.app.diffusion
          import ptq` succeeds, and `python -m deepcompressor.app.diffusion.ptq
          --help` prints its usage

Linux behaviour is unchanged: both changes are inside a sys.platform guard or
add an argument that was already the implied default.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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