Is this for only Linux? ImportError: cannot import name 'quantize_' from 'torchao.quantization'

FurkanGozukara: <p>I installed on windows and failing</p>
<p>from torchao.quantization import quantize_</p>
<p>pip freeze</p>
<pre><code class="lang-auto">Microsoft Windows [Version 10.0.19045.4894]
(c) Microsoft Corporation. All rights reserved.

R:\CogVideoX_v1\CogVideoX_SECourses\venv\Scripts&gt;activate

(venv) R:\CogVideoX_v1\CogVideoX_SECourses\venv\Scripts&gt;pip freeze
accelerate==0.34.2
aiofiles==23.2.1
annotated-types==0.7.0
anyio==4.6.0
certifi==2024.8.30
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
contourpy==1.3.0
cycler==0.12.1
decorator==4.4.2
diffusers @ git+https://github.com/huggingface/diffusers.git@665c6b47a23bc841ad1440c4fe9cbb1782258656
distro==1.9.0
einops==0.8.0
exceptiongroup==1.2.2
fastapi==0.115.0
ffmpy==0.4.0
filelock==3.16.1
fonttools==4.54.1
fsspec==2024.9.0
gradio==4.44.0
gradio_client==1.3.0
h11==0.14.0
httpcore==1.0.5
httpx==0.27.2
huggingface-hub==0.25.1
idna==3.10
imageio==2.35.1
imageio-ffmpeg==0.5.1
importlib_metadata==8.5.0
importlib_resources==6.4.5
Jinja2==3.1.4
jiter==0.5.0
kiwisolver==1.4.7
markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib==3.9.2
mdurl==0.1.2
moviepy==1.0.3
mpmath==1.3.0
networkx==3.3
numpy==1.26.0
openai==1.48.0
opencv-python==4.10.0.84
orjson==3.10.7
packaging==24.1
pandas==2.2.3
Pillow==9.5.0
proglog==0.1.10
psutil==6.0.0
pydantic==2.9.2
pydantic_core==2.23.4
pydub==0.25.1
Pygments==2.18.0
pyparsing==3.1.4
python-dateutil==2.9.0.post0
python-multipart==0.0.10
pytz==2024.2
PyYAML==6.0.2
regex==2024.9.11
requests==2.32.3
rich==13.8.1
ruff==0.6.8
safetensors==0.4.5
scikit-video==1.1.11
scipy==1.14.1
semantic-version==2.10.0
sentencepiece==0.2.0
shellingham==1.5.4
six==1.16.0
sniffio==1.3.1
spandrel==0.4.0
starlette==0.38.6
sympy==1.13.3
tokenizers==0.20.0
tomlkit==0.12.0
torch==2.4.1+cu124
torchao==0.1
torchvision==0.19.1+cu124
tqdm==4.66.5
transformers==4.45.0
triton @ https://huggingface.co/MonsterMMORPG/SECourses/resolve/main/triton-3.0.0-cp310-cp310-win_amd64.whl
typer==0.12.5
typing_extensions==4.12.2
tzdata==2024.2
urllib3==2.2.3
uvicorn==0.30.6
websockets==12.0
xformers==0.0.28.post1
zipp==3.20.2

(venv) R:\CogVideoX_v1\CogVideoX_SECourses\venv\Scripts&gt;
</code></pre>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\transformers\utils\import_utils.py", line 1764, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "C:\Python3108\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "&lt;frozen importlib._bootstrap&gt;", line 1050, in _gcd_import
  File "&lt;frozen importlib._bootstrap&gt;", line 1027, in _find_and_load
  File "&lt;frozen importlib._bootstrap&gt;", line 1006, in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 688, in _load_unlocked
  File "&lt;frozen importlib._bootstrap_external&gt;", line 883, in exec_module
  File "&lt;frozen importlib._bootstrap&gt;", line 241, in _call_with_frames_removed
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\transformers\models\t5\modeling_t5.py", line 38, in &lt;module&gt;
    from ...modeling_utils import PreTrainedModel
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\transformers\modeling_utils.py", line 58, in &lt;module&gt;
    from .quantizers import AutoHfQuantizer, HfQuantizer
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\transformers\quantizers\__init__.py", line 14, in &lt;module&gt;
    from .auto import AutoHfQuantizer, AutoQuantizationConfig
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\transformers\quantizers\auto.py", line 42, in &lt;module&gt;
    from .quantizer_torchao import TorchAoHfQuantizer
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\transformers\quantizers\quantizer_torchao.py", line 35, in &lt;module&gt;
    from torchao.quantization import quantize_
ImportError: cannot import name 'quantize_' from 'torchao.quantization' (R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\torchao\quantization\__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\diffusers\utils\import_utils.py", line 830, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "C:\Python3108\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "&lt;frozen importlib._bootstrap&gt;", line 1050, in _gcd_import
  File "&lt;frozen importlib._bootstrap&gt;", line 1027, in _find_and_load
  File "&lt;frozen importlib._bootstrap&gt;", line 1006, in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 688, in _load_unlocked
  File "&lt;frozen importlib._bootstrap_external&gt;", line 883, in exec_module
  File "&lt;frozen importlib._bootstrap&gt;", line 241, in _call_with_frames_removed
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\diffusers\pipelines\cogvideo\pipeline_cogvideox.py", line 21, in &lt;module&gt;
    from transformers import T5EncoderModel, T5Tokenizer
  File "&lt;frozen importlib._bootstrap&gt;", line 1075, in _handle_fromlist
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\transformers\utils\import_utils.py", line 1755, in __getattr__
    value = getattr(module, name)
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\transformers\utils\import_utils.py", line 1754, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\transformers\utils\import_utils.py", line 1766, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.models.t5.modeling_t5 because of the following error (look up to see its traceback):
cannot import name 'quantize_' from 'torchao.quantization' (R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\torchao\quantization\__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python3108\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python3108\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 39, in &lt;module&gt;
    cli.main()
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "R:\CogVideoX_v1\CogVideoX_SECourses\app.py", line 14, in &lt;module&gt;
    from diffusers import (
  File "&lt;frozen importlib._bootstrap&gt;", line 1075, in _handle_fromlist
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\diffusers\utils\import_utils.py", line 821, in __getattr__
    value = getattr(module, name)
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\diffusers\utils\import_utils.py", line 821, in __getattr__
    value = getattr(module, name)
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\diffusers\utils\import_utils.py", line 820, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\diffusers\utils\import_utils.py", line 832, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import diffusers.pipelines.cogvideo.pipeline_cogvideox because of the following error (look up to see its traceback):
Failed to import transformers.models.t5.modeling_t5 because of the following error (look up to see its traceback):
cannot import name 'quantize_' from 'torchao.quantization' (R:\CogVideoX_v1\CogVideoX_SECourses\venv\lib\site-packages\torchao\quantization\__init__.py)
Press any key to continue . . .
</code></pre>

zhaoxiandong27: <p>I solved the problem by  <code>pip install torchao --upgrade</code>.</p>

jerryzh168: <p>yeah it’s because torchao version is too low, it shows 0.1, this is answered in <a href="https://github.com/pytorch/ao/issues/957" class="inline-onebox" rel="noopener nofollow ugc">is this only for linux? · Issue #957 · pytorch/ao · GitHub</a> I think</p>