Skip to content

AttributeError: module 'mpmath' has no attribute 'rational' #2209

@underflow101

Description

@underflow101

Traceback

$ python3 -m examples.portable.scripts.export --model_name="add"

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.12_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/opt/homebrew/Cellar/python@3.10/3.10.12_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/Users/user/git/laboratory/executorch/examples/portable/__init__.py", line 7, in <module>
    from .utils import export_to_edge, export_to_exec_prog, save_pte_program
  File "/Users/user/git/laboratory/executorch/examples/portable/utils.py", line 11, in <module>
    import executorch.exir as exir
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/executorch/exir/__init__.py", line 9, in <module>
    from executorch.exir.capture import (
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/executorch/exir/capture/__init__.py", line 9, in <module>
    from executorch.exir.capture._capture import (
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/executorch/exir/capture/_capture.py", line 12, in <module>
    import torch
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/torch/__init__.py", line 1540, in <module>
    from . import masked
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/torch/masked/__init__.py", line 3, in <module>
    from ._ops import (
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/torch/masked/_ops.py", line 11, in <module>
    from torch._prims_common import corresponding_real_dtype
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/torch/_prims_common/__init__.py", line 23, in <module>
    import sympy
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/sympy/__init__.py", line 30, in <module>
    from sympy.core.cache import lazy_function
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/sympy/core/__init__.py", line 9, in <module>
    from .expr import Expr, AtomicExpr, UnevaluatedExpr
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/sympy/core/expr.py", line 4159, in <module>
    from .mul import Mul
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/sympy/core/mul.py", line 2193, in <module>
    from .numbers import Rational
  File "/Users/user/.virtualenvs/executorch/lib/python3.10/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'

Environment

  • MacOS
  • Python3.10.12

How to reproduce the issue

  • Follow every steps in the document, except that I used virtualenvwrapper.
To be specific... (Click to open)
$ git clone --branch v0.1.0 https://github.com/pytorch/executorch.git
$ mkvirtualenv executorch -p python3.10
$ cd executorch
$ git submodule sync
$ git submodule update --init
$ pip install cmake
$ ./install_requirements.sh
$ export PATH="/Users/user/git/laboratory/executorch/third-party/flatbuffers/cmake-out:${PATH}"
$ bash /Users/user/git/laboratory/executorch/build/install_flatc.sh
$ python3 -m examples.portable.scripts.export --model_name="add"

How to solve the issue locally

  • Do the following:
$ pip install mpmath==1.3.0

Collecting mpmath==1.3.0
  Downloading mpmath-1.3.0-py3-none-any.whl.metadata (8.6 kB)
Using cached mpmath-1.3.0-py3-none-any.whl (536 kB)
Installing collected packages: mpmath
  Attempting uninstall: mpmath
    Found existing installation: mpmath 1.4.0a0
    Uninstalling mpmath-1.4.0a0:
      Successfully uninstalled mpmath-1.4.0a0
Successfully installed mpmath-1.3.0

How does this local solution helps

$ python3 -m examples.portable.scripts.export --model_name="add"

[INFO 2024-03-03 01:42:59,555 utils.py:35] Core ATen graph:
graph():
    %arg0_1 : [num_users=3] = placeholder[target=arg0_1]
    %arg1_1 : [num_users=1] = placeholder[target=arg1_1]
    %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%arg0_1, %arg1_1), kwargs = {})
    %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add, %arg0_1), kwargs = {})
    %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_1, %arg0_1), kwargs = {})
    %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_2, %add_2), kwargs = {})
    return (add_3,)
[INFO 2024-03-03 01:42:59,583 utils.py:50] Exported graph:
graph():
    %arg0_1 : [num_users=3] = placeholder[target=arg0_1]
    %arg1_1 : [num_users=1] = placeholder[target=arg1_1]
    %aten_add_tensor : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.add.Tensor](args = (%arg0_1, %arg1_1), kwargs = {})
    %aten_add_tensor_1 : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.add.Tensor](args = (%aten_add_tensor, %arg0_1), kwargs = {})
    %aten_add_tensor_2 : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.add.Tensor](args = (%aten_add_tensor_1, %arg0_1), kwargs = {})
    %aten_add_tensor_3 : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.add.Tensor](args = (%aten_add_tensor_2, %aten_add_tensor_2), kwargs = {})
    return (aten_add_tensor_3,)
/Users/user/.virtualenvs/executorch/lib/python3.10/site-packages/torch/utils/_pytree.py:590: UserWarning: pytree_to_str is deprecated. Please use treespec_dumps
  warnings.warn("pytree_to_str is deprecated. Please use treespec_dumps")
[INFO 2024-03-03 01:42:59,623 utils.py:86] Saved exported program to add.pte

Metadata

Metadata

Assignees

Labels

module: build/installIssues related to the cmake and buck2 builds, and to installing ExecuTorchtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions