ImportError: cannot import name 'AutoModelForCausalLM' from 'modelscope' (/opt/conda/lib/python3.8/site-packages/modelscope/init.py)
y遇到了同样的问题
解决办法
pip install transformers
观察源代码发现以下内容
from typing import TYPE_CHECKING
from modelscope.utils.import_utils import (LazyImportModule,
                                           is_transformers_available)
from .utils.automodel_utils import fix_transformers_upgrade
if TYPE_CHECKING:
    from .exporters import Exporter, TfModelExporter, TorchModelExporter
    from .hub.api import HubApi
    from .hub.check_model import check_local_model_is_latest, check_model_is_id
    from .hub.push_to_hub import push_to_hub, push_to_hub_async
    from .hub.snapshot_download import snapshot_download
    from .metrics import (
        AccuracyMetric, AudioNoiseMetric, BleuMetric, ImageColorEnhanceMetric,
        ImageColorizationMetric, ImageDenoiseMetric, ImageInpaintingMetric,
        ImageInstanceSegmentationCOCOMetric, ImagePortraitEnhancementMetric,
        ImageQualityAssessmentDegradationMetric,
        ImageQualityAssessmentMosMetric, LossMetric, Metric,
        MovieSceneSegmentationMetric, OCRRecognitionMetric, PplMetric,
        ReferringVideoObjectSegmentationMetric, SequenceClassificationMetric,
        TextGenerationMetric, TextRankingMetric, TokenClassificationMetric,
        VideoFrameInterpolationMetric, VideoStabilizationMetric,
        VideoSummarizationMetric, VideoSuperResolutionMetric,
        task_default_metrics)
    from .models import Model, TorchModel
    from .msdatasets import MsDataset
    from .pipelines import Pipeline, pipeline
    from .preprocessors import Preprocessor
    from .trainers import (EpochBasedTrainer, Hook, Priority, TrainingArgs,
                           build_dataset_from_file)
    from .utils.constant import Tasks
    if is_transformers_available():
        from .utils.hf_util import AutoConfig, GPTQConfig, AwqConfig, BitsAndBytesConfig
        from .utils.hf_util import (AutoModel, AutoModelForCausalLM,
                                    AutoModelForSeq2SeqLM,
                                    AutoModelForSequenceClassification,
                                    AutoModelForTokenClassification,
                                    AutoTokenizer, GenerationConfig,
                                    AutoImageProcessor, BatchFeature)
is_transformers_available这个判断是在判断transformers是否存在
基于ModelScope进行推理报错显示:
Traceback (most recent call last):
  File "fine_tuning.py", line 24, in 
    from funasr.utils.modelscope_param import modelscope_args
ModuleNotFoundError: No module named 'funasr.utils.modelscope_param'
如何解决?
根据你提供的错误信息,你在导入 modelscope 时遇到了 ImportError。具体地,它指出无法从 modelscope 中导入 AutoModelForCausalLM。
这个错误可能是由以下几个原因之一引起的:
模块版本不匹配:确保你安装的 modelscope 版本与你正在使用的代码或文档所引用的版本一致。你可以尝试更新 modelscope,或者明确指定所需的版本。
安装问题:检查你的 modelscope 安装是否成功。有时安装过程可能会中断或出现错误。你可以尝试重新安装 modelscope,并确保安装过程没有报错。
名称错误:确认 AutoModelForCausalLM 是否是 modelscope 模块中的有效名称。可能是由于名称拼写错误或模块中没有定义该名称导致的。你可以查阅 modelscope 的文档以确定正确的导入名称。
我注意到你的环境应该是conda,在命令行中运行pip命令,注意目前激活的conda环境
>>>conda activate env_name
env_name替换成你自己的环境名称,再进行pip install
ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!欢迎加入技术交流群:微信公众号:魔搭ModelScope社区,钉钉群号:44837352