nod-ai / SHARK

SHARK - High Performance Machine Learning Distribution
Apache License 2.0
1.4k stars 169 forks source link

"AttributeError: module 'mpmath' has no attribute 'rational'" when recreating .venv (+workaround) #2095

Open one-lithe-rune opened 4 months ago

one-lithe-rune commented 4 months ago

Found this when trying to setup the .venv on Linux. But this happens for me on both SHARK-1.0 and sd-studio2 branches, on both Windows and Linux.

The workaround is to do pip install mpmath==1.3.0. But I'm guessing its an upstream requirements problem rather than a SHARK requirements one?

(shark1.venv) PS C:\develop\SHARK> shark-run
72175701 (HEAD -> SHARK-1.0, tag: 20240126.1139, upstream/SHARK-1.0, origin/SHARK-1.0) SDXL tweaks (#2072)
On branch SHARK-1.0
Your branch is up to date with 'upstream/SHARK-1.0'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        apps/shark_studio/web/models/

nothing added to commit but untracked files present (use "git add" to track)
Traceback (most recent call last):
  File "C:\develop\SHARK\apps\stable_diffusion\web\index.py", line 5, in <module>
    import apps.stable_diffusion.web.utils.app as app
  File "C:\develop\SHARK\apps\stable_diffusion\web\utils\app.py", line 10, in <module>
    from apps.stable_diffusion.src import args
  File "C:\develop\SHARK\apps\stable_diffusion\src\__init__.py", line 1, in <module>
    from apps.stable_diffusion.src.utils import (
  File "C:\develop\SHARK\apps\stable_diffusion\src\utils\__init__.py", line 12, in <module>
    from apps.stable_diffusion.src.utils.sd_annotation import sd_model_annotation
  File "C:\develop\SHARK\apps\stable_diffusion\src\utils\sd_annotation.py", line 3, in <module>
    from shark.model_annotation import model_annotation, create_context
  File "C:\develop\SHARK\shark\__init__.py", line 4, in <module>
    from torch._dynamo import register_backend
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\torch\_dynamo\__init__.py", line 2, in <module>
    from . import allowed_functions, convert_frame, eval_frame, resume_execution
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\torch\_dynamo\allowed_functions.py", line 30, in <module>
    from .utils import hashable, is_safe_constant, NP_SUPPORTED_MODULES
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\torch\_dynamo\utils.py", line 89, in <module>
    import torch.fx.experimental.symbolic_shapes
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\torch\fx\experimental\symbolic_shapes.py", line 38, in <module>
    from torch.utils._sympy.functions import FloorDiv, Mod, IsNonOverlappingAndDenseIndicator
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\torch\utils\_sympy\functions.py", line 1, in <module>
    import sympy
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\sympy\__init__.py", line 30, in <module>
    from sympy.core.cache import lazy_function
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\sympy\core\__init__.py", line 9, in <module>
    from .expr import Expr, AtomicExpr, UnevaluatedExpr
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\sympy\core\expr.py", line 4159, in <module>
    from .mul import Mul
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\sympy\core\mul.py", line 2193, in <module>
    from .numbers import Rational
  File "C:\develop\SHARK\shark1.venv\Lib\site-packages\sympy\core\numbers.py", line 4567, in <module>
    _sympy_converter[type(mpmath.rational.mpq(1, 2))] = sympify_mpmath_mpq
                          ^^^^^^^^^^^^^^^
AttributeError: module 'mpmath' has no attribute 'rational'

Looks like its picking up an alpha version of that dependency somehow:

(shark1.venv) PS C:\develop\SHARK>pip show mpmath
Name: mpmath
Version: 1.4.0a0
Summary: Python library for arbitrary-precision floating-point arithmetic
Home-page:
Author:
Author-email: Fredrik Johansson <fredrik.johansson@gmail.com>
License: BSD
Location: C:\develop\SHARK\shark1.venv\Lib\site-packages
Requires:
Required-by: sympy
summer996 commented 4 months ago

sudo pip install mpmath==1.3.0

one-lithe-rune commented 4 months ago

PR for add the workaround to the Shark-1.0 requirements: #2099 I believe Studio2 should be fixed by the merged https://github.com/nod-ai/SHARK-Turbine/pull/477