ZenCtrl icon indicating copy to clipboard operation
ZenCtrl copied to clipboard

Missing requirements

Open SoftologyPro opened this issue 7 months ago • 28 comments

After installing requirements.txt and starting app.py it complains "No module named 'flux'" pip install flux app.py now gives

Traceback (most recent call last):
  File "D:\Tests\ZenCtrl\ZenCtrl\app\gradio_app.py", line 9, in <module>
    from flux.condition import Condition
ModuleNotFoundError: No module named 'flux.condition'

What version of flux is needed? Can you update requirements.txt for all requirements?

SoftologyPro avatar May 08 '25 00:05 SoftologyPro

hello @SoftologyPro when you cloned the repository , it came with a flux folder :https://github.com/FotographerAI/ZenCtrl/tree/kane/flux , when running the app.py , please make sure the nesting of the path is matching when calling the class. You don't need to install any other requirements

saliou-k avatar May 08 '25 12:05 saliou-k

Thank you. I had to copy the contents of the app folder to the root directory. Then it finds the needed flux. But now when app starts I get a missing error

Traceback (most recent call last):
  File "D:\Tests\ZenCtrl\ZenCtrl\gradio_app.py", line 119, in <module>
    examples=get_samples(),
  File "D:\Tests\ZenCtrl\ZenCtrl\gradio_app.py", line 101, in get_samples
    return [[Image.open(sample["image"]), sample["text"]] for sample in sample_list]
  File "D:\Tests\ZenCtrl\ZenCtrl\gradio_app.py", line 101, in <listcomp>
    return [[Image.open(sample["image"]), sample["text"]] for sample in sample_list]
  File "D:\Tests\ZenCtrl\ZenCtrl\venv\lib\site-packages\PIL\Image.py", line 3505, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'samples/1.png'

Can you add that to the samples directory so app starts?

SoftologyPro avatar May 08 '25 13:05 SoftologyPro

let me add a push now

saliou-k avatar May 08 '25 13:05 saliou-k

@SoftologyPro updated the samples . By the way i think you noticed , but to load our model you will have to download it from our HF repo : https://huggingface.co/fotographerai/zenctrl_tools/tree/main/weights/zen2con_1024_10000 , you can download this wait and put the path here : https://github.com/FotographerAI/ZenCtrl/blob/b6d814661ba250285a621d60b09c3084880ab57f/app/gradio_app.py#L42

saliou-k avatar May 08 '25 13:05 saliou-k

@saliou-k I also recommend creating a predefined path; See *** Fix lora path below.

@echo off
echo *** Cloning and setup
git clone https://github.com/FotographerAI/ZenCtrl.git
cd ZenCtrl
python -m venv venv
call venv\scripts\activate.bat

echo *** Installing dependencies
pip install --upgrade pip wheel setuptools
pip install torch==2.7.0+cu128 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
pip install -U "triton-windows>=3.3"
pip install https://huggingface.co/datasets/Softology-Pro/VoC/resolve/main/flash_attn-2.7.4.post1-cp310-cp310-win_amd64.whl
pip install -r requirements.txt

echo *** Setup weights
mkdir weights\zen2con_1440_17000
curl -L https://huggingface.co/fotographerai/zenctrl_tools/resolve/main/weights/zen2con_1440_17000/pytorch_lora_weights.safetensors -o weights\zen2con_1440_17000\pytorch_lora_weights.safetensors

echo *** Fix lora path
echo with open('app/gradio_app.py','r') as f: t=f.read().replace('path/to/weight/pytorch_lora_weights.safetensors','weights/zen2con_1440_17000/pytorch_lora_weights.safetensors'); open('app/gradio_app.py','w').write(t) > fix.py

To avoid "No module named 'flux,'" I think this is the right way to start is?:

python -m app.gradio_app

Katehuuh avatar May 08 '25 13:05 Katehuuh

@Katehuuh yes thanks , i was about to update the readme with the commands needed for better clarity

saliou-k avatar May 08 '25 13:05 saliou-k

To avoid "No module named 'flux,'" I think this is the right way to start is?:

python -m app.gradio_app

Well, doing so:

(venv) C:\ZenCtrl>python -m app.gradio_app
Fetching 2 files: 100%|██████████████████████████████████████████████████████████████████████████| 2/2 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "C:\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\ZenCtrl\app\gradio_app.py", line 123, in <module>
    init_pipeline()
  File "C:\ZenCtrl\app\gradio_app.py", line 24, in init_pipeline
    transformer_model = FluxTransformer2DModel.from_pretrained(
  File "C:\ZenCtrl\venv\lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
  File "C:\ZenCtrl\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 886, in from_pretrained
    accelerate.load_checkpoint_and_dispatch(
  File "C:\ZenCtrl\venv\lib\site-packages\accelerate\big_modeling.py", line 617, in load_checkpoint_and_dispatch
    load_checkpoint_in_model(
  File "C:\ZenCtrl\venv\lib\site-packages\accelerate\utils\modeling.py", line 1915, in load_checkpoint_in_model
    loaded_checkpoint = load_state_dict(checkpoint_file, device_map=device_map)
  File "C:\ZenCtrl\venv\lib\site-packages\accelerate\utils\modeling.py", line 1707, in load_state_dict
    return torch.load(checkpoint_file, map_location=torch.device("cpu"))
  File "C:\ZenCtrl\venv\lib\site-packages\torch\serialization.py", line 1524, in load
    raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.
        (1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
        (2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
        WeightsUnpickler error: Unsupported global: GLOBAL torchao.dtypes.affine_quantized_tensor.PlainAQTLayout was not an allowed global by default. Please use `torch.serialization.add_safe_globals([torchao.dtypes.affine_quantized_tensor.PlainAQTLayout])` or the `torch.serialization.safe_globals([torchao.dtypes.affine_quantized_tensor.PlainAQTLayout])` context manager to allowlist this global if you trust this class/function.

Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.

Katehuuh avatar May 08 '25 14:05 Katehuuh

Updated the readme . Which ver of Pytorch do you have , we are running with 2.7.0 , didn't came through this error , but it seems you would need to add a safety checker , which is a first for me even

saliou-k avatar May 08 '25 14:05 saliou-k

@Katehuuh let me know if it worked after doing this : transformer_model = FluxTransformer2DModel.from_pretrained( "your/model/path", torch_dtype=torch.float16, low_cpu_mem_usage=True, use_safetensors=True, **{"weights_only": False} #add this parameter )

saliou-k avatar May 08 '25 14:05 saliou-k

Updated the readme . Which ver of Pytorch do you have , we are running with 2.7.0

Same torch==2.7.0, like my Install:

pip install torch==2.7.0+cu128 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128


@Katehuuh let me know if it worked after doing this : transformer_model = FluxTransformer2DModel.from_pretrained( "your/model/path", torch_dtype=torch.float16, low_cpu_mem_usage=True, use_safetensors=True, **{"weights_only": False} #add this parameter )

https://github.com/FotographerAI/ZenCtrl/blob/98bae76ea94bb1a0f3738e6a0b97da1e71eb773d/app/gradio_app.py#L26-L27 by

            torch_dtype=torch.float16,
            use_safetensors=True,
            **{"weights_only": False}

log

  File "C:\ZenCtrl\app\gradio_app.py", line 3, in <module>
    from torchao.dtypes.affine_quantized_tensor import PlainAQTLayout
ImportError: cannot import name 'PlainAQTLayout' from 'torchao.dtypes.affine_quantized_tensor' (C:\ZenCtrl\venv\lib\site-packages\torchao\dtypes\affine_quantized_tensor.py)

Katehuuh avatar May 08 '25 15:05 Katehuuh

Updated the readme . Which ver of Pytorch do you have , we are running with 2.7.0

Same torch==2.7.0, like my Install:

pip install torch==2.7.0+cu128 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

@Katehuuh let me know if it worked after doing this : transformer_model = FluxTransformer2DModel.from_pretrained( "your/model/path", torch_dtype=torch.float16, low_cpu_mem_usage=True, use_safetensors=True, **{"weights_only": False} #add this parameter )

ZenCtrl/app/gradio_app.py

Lines 26 to 27 in 98bae76 torch_dtype=torch.bfloat16, use_safetensors=False,

by

            torch_dtype=torch.float16,
            use_safetensors=True,
            **{"weights_only": False}

log

  File "C:\ZenCtrl\app\gradio_app.py", line 3, in <module>
    from torchao.dtypes.affine_quantized_tensor import PlainAQTLayout
ImportError: cannot import name 'PlainAQTLayout' from 'torchao.dtypes.affine_quantized_tensor' (C:\ZenCtrl\venv\lib\site-packages\torchao\dtypes\affine_quantized_tensor.py)

Were you able to fix this? having similar issues

adeysif avatar May 11 '25 18:05 adeysif

I am also getting that same error. I'm running Torch 2.7 using RTX 5090. followed exact instructions. Need to change the launch command from. Python 3.10 python app/gradio_app.py to: python -m app.gradio_app But get the same error as above, tried a few fresh installs, and anything in the thread.

(venv) E:\ZenCtrl>python -m app.gradio_app W0511 14:27:42.416000 2985556 venv\Lib\site-packages\torch\distributed\elastic\multiprocessing\redirects.py:29] NOTE: Redirects are currently not supported in Windows or MacOs. Fetching 2 files: 100%|██████████████████████████████████████████████████████████████████████████| 2/2 [00:00<?, ?it/s] Traceback (most recent call last): File "C:\Users\kevin\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\kevin\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "E:\ZenCtrl\app\gradio_app.py", line 122, in init_pipeline() File "E:\ZenCtrl\app\gradio_app.py", line 24, in init_pipeline transformer_model = FluxTransformer2DModel.from_pretrained( File "E:\ZenCtrl\venv\lib\site-packages\huggingface_hub\utils_validators.py", line 114, in _inner_fn return fn(*args, **kwargs) File "E:\ZenCtrl\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 886, in from_pretrained accelerate.load_checkpoint_and_dispatch( File "E:\ZenCtrl\venv\lib\site-packages\accelerate\big_modeling.py", line 617, in load_checkpoint_and_dispatch load_checkpoint_in_model( File "E:\ZenCtrl\venv\lib\site-packages\accelerate\utils\modeling.py", line 1915, in load_checkpoint_in_model loaded_checkpoint = load_state_dict(checkpoint_file, device_map=device_map) File "E:\ZenCtrl\venv\lib\site-packages\accelerate\utils\modeling.py", line 1707, in load_state_dict return torch.load(checkpoint_file, map_location=torch.device("cpu")) File "E:\ZenCtrl\venv\lib\site-packages\torch\serialization.py", line 1524, in load raise pickle.UnpicklingError(_get_wo_message(str(e))) from None _pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. (1) In PyTorch 2.6, we changed the default value of the weights_only argument in torch.load from False to True. Re-running torch.load with weights_only set to False will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source. (2) Alternatively, to load with weights_only=True please check the recommended steps in the following error message. WeightsUnpickler error: Unsupported global: GLOBAL torchao.dtypes.affine_quantized_tensor.PlainAQTLayout was not an allowed global by default. Please use torch.serialization.add_safe_globals([torchao.dtypes.affine_quantized_tensor.PlainAQTLayout]) or the torch.serialization.safe_globals([torchao.dtypes.affine_quantized_tensor.PlainAQTLayout]) context manager to allowlist this global if you trust this class/function.

pupphelper avatar May 11 '25 18:05 pupphelper

Stuck (on Ubuntu) as well at

ImportError: cannot import name 'PlainAQTLayout' from 'torchao.dtypes.affine_quantized_tensor'

Clean installl, using torch 2.7.0 per requirements, etc. Tried multiple versions of torchdao (from 6.1 to latest).

**{"weights_only": False}

This did not work either. Only hackining serialization.py by forcibly inserting; weights_only = False into the load function would let me progress (yielding the error above). This is obviously not recommended as a long term solution.

ModuleNotFoundError: No module named 'flux.condition'

...can also be fixed by inserting into gradio_app.py;

import sys
sys.path.insert(0, "/path/to/your/ZenCtrl/")

IvoJager avatar May 12 '25 01:05 IvoJager

也不知道官方给的代码,自己有没有测试过。。。。

starinskycc avatar May 12 '25 02:05 starinskycc

Image

starinskycc avatar May 12 '25 02:05 starinskycc

Image

starinskycc avatar May 12 '25 02:05 starinskycc

Tried even older versions of torchao and 3.1 seems to get us the closest, though still plenty of errors (for example have to delete calls to some benchmarking code). It appears the ZenCtrl team is running some torchao nightly build from around the 3.1 era? It'd be great if they could test their own script and requirements.

IvoJager avatar May 12 '25 03:05 IvoJager

hey Guys , sorry for being late , we're checking the scripts making sure the dependencies and requirements are met and will update this in a bit

saliou-k avatar May 12 '25 03:05 saliou-k

pushing in a few hours after some tests , sorry for that ! would love for you to try out and let us know ! i am working on the comfy node too , that might take a bit more time

saliou-k avatar May 12 '25 03:05 saliou-k

3q

starinskycc avatar May 12 '25 04:05 starinskycc

Updated the readme . Which ver of Pytorch do you have , we are running with 2.7.0 , didn't came through this error , but it seems you would need to add a safety checker , which is a first for me even更新了 readme。你用的是哪个版本的 Pytorch?我们用的是 2.7.0,没有出现这个错误,但似乎你需要添加一个安全检查器,这对我来说还是第一次

torch2.7,按照官方教程安装,一样的错误。

Jandown avatar May 12 '25 10:05 Jandown

Hi guys , just running few more tests , in the meantime a patch was given by a community member hope this helps while we push our latest changes https://github.com/FotographerAI/ZenCtrl/issues/11#issue-3057249109

saliou-k avatar May 12 '25 16:05 saliou-k

Hi guys , just running few more tests , in the meantime a patch was given by a community member hope this helps while we push our latest changes #11 (comment)

For those who already bypassed this small issue, the big issue remains;

ImportError: cannot import name 'PlainAQTLayout' from 'torchao.dtypes.affine_quantized_tensor'

PlainAQTLayout appears to no longer exist in the versions/requirements the ZenCtrl team prescribes.

This may have something to do with the int8 quantized tensor model used. Would it be possible to use an alternative (fp8?) or more up-to-date model?

IvoJager avatar May 12 '25 23:05 IvoJager

Seems like the issue is this breaking change, which appears to make the int8wo model no longer compatible as of torchao 0.7+;

https://github.com/pytorch/ao/pull/1049

IvoJager avatar May 13 '25 08:05 IvoJager

me too ,how fix it ?

ws4349893 avatar May 16 '25 09:05 ws4349893

add setup.py from setuptools import setup, find_packages

setup( name="zenctrl", version="0.1", packages=find_packages(), install_requires=[ # Add your dependencies from requirements.txt here ] )

pip install -e .

ws4349893 avatar May 16 '25 09:05 ws4349893