google-ai-edge / ai-edge-torch

Supporting PyTorch models with the Google AI Edge TFLite runtime.
Apache License 2.0
364 stars 50 forks source link

Error when importing 0.3.0 #218

Closed scarlettekk closed 1 month ago

scarlettekk commented 1 month ago

Description of the bug:

I was trying to use the latest commit version to convert gemma2 since it seems like 0.2.0 doesn't support it. However, I can't even import it:

Traceback (most recent call last):
  File "/home/scarlett/git/gemma/convert.py", line 21, in <module>
    import ai_edge_torch
  File "/home/scarlett/.local/share/virtualenvs/gemma-U5bxnpzZ/lib/python3.11/site-packages/ai_edge_torch/__init__.py", line 16, in <module>
    from ai_edge_torch._convert.converter import convert
  File "/home/scarlett/.local/share/virtualenvs/gemma-U5bxnpzZ/lib/python3.11/site-packages/ai_edge_torch/_convert/converter.py", line 21, in <module>
    from ai_edge_torch._convert import conversion
  File "/home/scarlett/.local/share/virtualenvs/gemma-U5bxnpzZ/lib/python3.11/site-packages/ai_edge_torch/_convert/conversion.py", line 20, in <module>
    from ai_edge_torch import lowertools
  File "/home/scarlett/.local/share/virtualenvs/gemma-U5bxnpzZ/lib/python3.11/site-packages/ai_edge_torch/lowertools/__init__.py", line 16, in <module>
    from ._shim import *
  File "/home/scarlett/.local/share/virtualenvs/gemma-U5bxnpzZ/lib/python3.11/site-packages/ai_edge_torch/lowertools/_shim.py", line 25, in <module>
    from ai_edge_torch.lowertools import torch_xla_utils as utils
  File "/home/scarlett/.local/share/virtualenvs/gemma-U5bxnpzZ/lib/python3.11/site-packages/ai_edge_torch/lowertools/torch_xla_utils.py", line 29, in <module>
    from ai_edge_torch.lowertools import translate_recipe
  File "/home/scarlett/.local/share/virtualenvs/gemma-U5bxnpzZ/lib/python3.11/site-packages/ai_edge_torch/lowertools/translate_recipe.py", line 20, in <module>
    _ComputePrecision = quantizer.qtyping.ComputePrecision
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'ai_edge_quantizer.qtyping' has no attribute 'ComputePrecision'

Actual vs expected behavior:

Expected: The library imports normally

Actual: The library fails to import

Any other information you'd like to share?

Trying to use https://github.com/google-ai-edge/ai-edge-torch/blob/main/ai_edge_torch/generative/examples/gemma/convert_gemma2_to_tflite.py

pkgoogle commented 1 month ago

Hi @scarlettekk, how did you install the latest commit?

I was able to import properly the latest commit by doing this:

cd ai-edge-torch # my github root
git switch main # ensure you are on main branch
git pull # ensure you are up to date
pip install -e . # install the current code in your current environment, python=3.11 was previously installed
python
>>> import ai_edge_torch

Does this work if you start in a fresh environment? Thanks.

patrickzan commented 1 month ago

Hi @scarlettekk @pkgoogle, I also got the same error with python3.10 environment using the following approach, but when I switched to python3.11 and re-installed ai-edge-torch the same way, the error disappeared. Hope this is helpful.

cd ai-edge-torch # my github root
git switch main # ensure you are on main branch
git pull # ensure you are up to date
pip install -e . # install the current code in your current environment, python=3.11 was previously installed
python
>>> import ai_edge_torch
github-actions[bot] commented 1 month ago

Marking this issue as stale since it has been open for 7 days with no activity. This issue will be closed if no further activity occurs.

github-actions[bot] commented 1 month ago

This issue was closed because it has been inactive for 14 days. Please post a new issue if you need further assistance. Thanks!

johndpope commented 3 weeks ago

what version of tensorflow is necessary? nightly 2.19?

( need to make readme clear if its necessary to use later tensorflow release for nightly builds.)

UPDATE - that didn't work.

Screenshot from 2024-10-19 07-12-31

my pip freeze + also logs from install pip install -e . https://gist.github.com/johndpope/53edcfabfa59e8294323b3aa2d1cd2e3

johndpope commented 3 weeks ago

fix here - https://github.com/google-ai-edge/ai-edge-torch/issues/286