PKU-YuanGroup / MagicTime

MagicTime: Time-lapse Video Generation Models as Metamorphic Simulators
https://pku-yuangroup.github.io/MagicTime/
Apache License 2.0
1.31k stars 125 forks source link

Windows not supported? #32

Open SoftologyPro opened 5 months ago

SoftologyPro commented 5 months ago
    from multiprocessing.context import ForkProcess
ImportError: cannot import name 'ForkProcess' from 'multiprocessing.context' (D:\Python\lib\multiprocessing\context.py)

ForkProcess only on Unix? Any chance you can patch it for Windows compatibility too?

SHYuanBest commented 4 months ago

"from multiprocessing.context import ForkProcess" this line of code doesn't seem to be in our repo. Can you provide a more detailed error message? Our model also supports running on Windows, and this error looks like an issue with your Python environment.

SoftologyPro commented 4 months ago

Here is the complete output when I run python app.py

Traceback (most recent call last):
  File "D:\Tests\MagicTime\MagicTime\app.py", line 18, in <module>
    import spaces
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\spaces\__init__.py", line 10, in <module>
    from .zero.decorator import GPU
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\spaces\zero\decorator.py", line 21, in <module>
    from .wrappers import regular_function_wrapper
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\spaces\zero\wrappers.py", line 15, in <module>
    from multiprocessing.context import ForkProcess
ImportError: cannot import name 'ForkProcess' from 'multiprocessing.context' (D:\Python\lib\multiprocessing\context.py)

To help replicate the issue I created a batch file to do the install clean and create its own venv. Run this install.bat from any empty directory to do the install. Triton is removed as it does not work with Windows.

@echo off

echo *** Deleting MagicTime directory if it exists
if exist MagicTime\. rd /S /Q MagicTime

echo *** Cloning MagicTime repository
git clone https://github.com/PKU-YuanGroup/MagicTime
cd MagicTime

echo *** Creating venv
python -m venv venv
call venv\scripts\activate.bat

echo *** Removing triton from requirements.txt
type requirements.txt | findstr /v triton > stripped.txt
del requirements.txt
ren stripped.txt requirements.txt

echo *** Installing requirements.txt
python -m pip install --upgrade pip
pip install -r requirements.txt

echo *** Installing other required packages
pip uninstall -y xformers
pip install --no-cache-dir --ignore-installed --force-reinstall --no-warn-conflicts xformers==0.0.25 --index-url https://download.pytorch.org/whl/cu118
pip uninstall -y torch
pip uninstall -y torch
pip install --no-cache-dir --ignore-installed --force-reinstall --no-warn-conflicts torch==2.2.2+cu118 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

call venv\scripts\deactivate.bat
cd ..

echo *** Finished MagicTime install
echo.

And this batch file run.bat to run it once installed.

@echo off
cls
call MagicTime\venv\scripts\activate.bat
cd MagicTime
python app.py
cd..
call MagicTime\venv\scripts\deactivate.bat
SHYuanBest commented 4 months ago

I modified the code, you can try it now

SoftologyPro commented 4 months ago

OK, that got past the ForkProcess error. It now gives this error at startup as rm is not a Windows command.

### Cleaning cached examples ...
'rm' is not recognized as an internal or external command,
operable program or batch file.

It does still start the UI after that though. Clicking the examples does not work and gives these errors.

Traceback (most recent call last):
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\helpers.py", line 539, in load_from_cache
    value_as_dict = ast.literal_eval(value)
  File "D:\Python\lib\ast.py", line 110, in literal_eval
    return _convert(node_or_string)
  File "D:\Python\lib\ast.py", line 99, in _convert
    return dict(zip(map(_convert, node.keys),
  File "D:\Python\lib\ast.py", line 109, in _convert
    return _convert_signed_num(node)
  File "D:\Python\lib\ast.py", line 83, in _convert_signed_num
    return _convert_num(node)
  File "D:\Python\lib\ast.py", line 74, in _convert_num
    _raise_malformed_node(node)
  File "D:\Python\lib\ast.py", line 71, in _raise_malformed_node
    raise ValueError(msg + f': {node!r}')
ValueError: malformed node or string on line 1: <ast.Call object at 0x000001A4B98E90C0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\routes.py", line 737, in predict
    output = await route_utils.call_process_api(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\route_utils.py", line 276, in call_process_api
    output = await app.get_blocks().process_api(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\blocks.py", line 1928, in process_api
    result = await self.call_function(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\blocks.py", line 1514, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\anyio\to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 859, in run
    result = context.run(func, *args)
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\utils.py", line 833, in wrapper
    response = f(*args, **kwargs)
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\helpers.py", line 511, in load_example
    ] + self.load_from_cache(example_id)
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\helpers.py", line 551, in load_from_cache
    output.append(component.read_from_flag(value_to_use))
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\components\json_component.py", line 114, in read_from_flag
    return json.loads(payload)
  File "D:\Python\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "D:\Python\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "D:\Python\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
SHYuanBest commented 4 months ago

If you are running on Windows, you can try changing “rm ”to “del

SoftologyPro commented 4 months ago

Yes, running on Windows. Can you add some code so the rm or rd works? Detect Windows and if so use os.system(f"rd gradio_cached_examples /s/q") otherwise use the existing rm linux command.

Once that change is made and the UI is launched, clicking the examples still gives these errors...

Traceback (most recent call last):
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\helpers.py", line 539, in load_from_cache
    value_as_dict = ast.literal_eval(value)
  File "D:\Python\lib\ast.py", line 110, in literal_eval
    return _convert(node_or_string)
  File "D:\Python\lib\ast.py", line 99, in _convert
    return dict(zip(map(_convert, node.keys),
  File "D:\Python\lib\ast.py", line 109, in _convert
    return _convert_signed_num(node)
  File "D:\Python\lib\ast.py", line 83, in _convert_signed_num
    return _convert_num(node)
  File "D:\Python\lib\ast.py", line 74, in _convert_num
    _raise_malformed_node(node)
  File "D:\Python\lib\ast.py", line 71, in _raise_malformed_node
    raise ValueError(msg + f': {node!r}')
ValueError: malformed node or string on line 1: <ast.Call object at 0x0000019D870739A0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\routes.py", line 737, in predict
    output = await route_utils.call_process_api(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\route_utils.py", line 276, in call_process_api
    output = await app.get_blocks().process_api(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\blocks.py", line 1928, in process_api
    result = await self.call_function(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\blocks.py", line 1514, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\anyio\to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 859, in run
    result = context.run(func, *args)
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\utils.py", line 833, in wrapper
    response = f(*args, **kwargs)
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\helpers.py", line 511, in load_example
    ] + self.load_from_cache(example_id)
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\helpers.py", line 551, in load_from_cache
    output.append(component.read_from_flag(value_to_use))
  File "D:\Tests\MagicTime\MagicTime\venv\lib\site-packages\gradio\components\json_component.py", line 114, in read_from_flag
    return json.loads(payload)
  File "D:\Python\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "D:\Python\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "D:\Python\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
SoftologyPro commented 4 months ago

The reason for this fix request is that is that users have requested that I added support for MagicTime into Visions of Chaos. I can automate the install, but having you edit your code to support windows (with the rm vs del) would make things easier, and allow MagicTime to be installed easily on any Windows PC.

I could just auto-edit the code for del when the user finishes the install, but it would be good to have a fix for the examples failing when clicked. Thanks if you could have a look and fix that.

SHYuanBest commented 4 months ago

thanks for your interest. You can try changing _os.system(f"rm -rf gradio_cachedexamples/") to _os.system(f"rmdir /s /q gradio_cachedexamples"), and keep the other codes unchanged. Theoretically, it can be adapted to Windows after modification.

SoftologyPro commented 4 months ago

OK, we may have some language issues. Can you make the change in ytour code. Something to detect if Windows and run the Windows code.

Also, the examples fail. Click any of the lower examples in the gradio GUI and you get the errors I posted above.

SHYuanBest commented 4 months ago

I don’t have a Windows machine with a GPU to debug right now, so I may need to fix this later.

SoftologyPro commented 4 months ago

OK, I won;t bother with it for now then. If you do make the change (and fix the other bug) in the future let me know and I will add it to Visions of Chaos for Windows users.

SHYuanBest commented 4 months ago

Thank you for your understanding and attention, I will definitely fix this problem


发件人: SoftologyPro @.> 发送时间: 2024年7月5日 10:43 收件人: PKU-YuanGroup/MagicTime @.> 抄送: Shenghai Yuan @.>; Comment @.> 主题: Re: [PKU-YuanGroup/MagicTime] Windows not supported? (Issue #32)

OK, I won;t bother with it for now then. If you do make the change (and fix the other bug) in the future let me know and I will add it to Visions of Chaos for Windows users.

― Reply to this email directly, view it on GitHubhttps://github.com/PKU-YuanGroup/MagicTime/issues/32#issuecomment-2209895045, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BBTMABSBL5VHLVEYQ3U7GGTZKYB37AVCNFSM6AAAAABIX3QK36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBZHA4TKMBUGU. You are receiving this because you commented.Message ID: @.***>