Skip to content

transformers import_utils.py module 'torch' has no attribute 'fx' #27534

Description

@R0k1e

System Info

env: transformers=4.35.2, torch = 1.12.1+cu113, Ubuntu 20.04.6 LTS python=3.10
when I write this sentence "from transformers import LlamaForCausalLM, LlamaTokenizer, AutoTokenizer, AutoModelForCausalLM", It tell me it cant find fx in torch. I inspect the doc of torch version and found there is fx module in this version. And when I use the console to import torch.fx, there is no fault happened. And the I add the import torch.fx before the "from transformers import LlamaForCausalLM, LlamaTokenizer, AutoTokenizer, AutoModelForCausalLM", the error misses.

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

  1. install the llama according to its readme
  2. install the torch = 1.12.1+cu113
  3. write a footprint including following sentences
    import argparse
    import json
    import os
    import time

import pandas as pd
import tensor_parallel as tp
import torch

from tqdm import tqdm
from transformers import LlamaForCausalLM, LlamaTokenizer, AutoTokenizer, AutoModelForCausalLM

and then the error occur
from transformers import LlamaForCausalLM, LlamaTokenizer, AutoTokenizer, AutoModelForCausalLM
File "", line 1075, in _handle_fromlist
File "/miniconda3/envs/llama-7b/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1344, in getattr
value = getattr(module, name)
File "/miniconda3/envs/llama-7b/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1343, in getattr
module = self._get_module(self._class_to_module[name])
File "/miniconda3/envs/llama-7b/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1355, in _get_module
raise RuntimeError(
RuntimeError: Failed to import transformers.models.llama.modeling_llama because of the following error (look up to see its traceback):
module 'torch' has no attribute 'fx'

Expected behavior

no error occur

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions