求助: 运行模型时报错module 'megatron_util.mpu' has no attribute 'get_model_parallel_rank'

本文涉及的产品
NLP自然语言处理_基础版,每接口每天50万次
NLP自然语言处理_高级版,每接口累计50万次
NLP 自学习平台,3个模型定制额度 1个月
简介: 运行ZhipuAI/Multilingual-GLM-Summarization-zh的官方代码范例时,报错AttributeError: MGLMTextSummarizationPipeline: module 'megatron_util.mpu' has no attribute 'get_model_parallel_rank'环境是基于ModelScope官方docker镜像,尝试了各个版本结果都是一样的。

运行ZhipuAI/Multilingual-GLM-Summarization-zh的官方代码范例时,报错AttributeError: MGLMTextSummarizationPipeline: module 'megatron_util.mpu' has no attribute 'get_model_parallel_rank'
环境是基于ModelScope官方docker镜像,尝试了各个版本结果都是一样的。也尝试使用
pip uninstall megatron_util && pip install megatron_util -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html重新安装各个版本的megatron_util,但是还是没有效果。
具体报错内容如下:

root@dc19cfd686f9:/app# python test.py 
2023-11-19 03:45:04,162 - modelscope - INFO - PyTorch version 1.11.0+cu113 Found.
2023-11-19 03:45:04,163 - modelscope - INFO - Loading ast index from /mnt/workspace/.cache/modelscope/ast_indexer
2023-11-19 03:45:04,181 - modelscope - INFO - Loading done! Current index file version is 1.6.1, with md5 7ef0ea14f2ab92de0a689c4b4f9dd76d and a total number of 849 components indexed
2023-11-19 03:45:05,183 - modelscope - INFO - Model revision not specified, use the latest revision: v1.0.1
No CUDA runtime is found, using CUDA_HOME='/usr/local/cuda'
[2023-11-19 03:45:06,171] [INFO] [real_accelerator.py:158:get_accelerator] Setting ds_accelerator to cuda (auto detect)
WARNING: No training data specified
using world size: 1 and model-parallel size: 1 
 > using dynamic loss scaling
megatron initialized twice
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /opt/conda/lib/python3.7/site-packages/modelscope/utils/registry.py:212 in build_from_cfg        │
│                                                                                                  │
│   209 │   │   if hasattr(obj_cls, '_instantiate'):                                               │
│   210 │   │   │   return obj_cls._instantiate(**args)                                            │
│   211 │   │   else:                                                                              │
│ ❱ 212 │   │   │   return obj_cls(**args)                                                         │
│   213 │   except Exception as e:                                                                 │
│   214 │   │   # Normal TypeError does not print class name.                                      │
│   215 │   │   raise type(e)(f'{obj_cls.__name__}: {e}')                                          │
│                                                                                                  │
│ /opt/conda/lib/python3.7/site-packages/modelscope/pipelines/nlp/mglm_text_summarization_pipeline │
│ .py:29 in __init__                                                                               │
│                                                                                                  │
│   26 │   │   │   │    *args,                                                                     │
│   27 │   │   │   │    **kwargs):                                                                 │
│   28 │   │   model = MGLMForTextSummarization(model) if isinstance(model,                        │
│ ❱ 29 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │     str) else model               │
│   30 │   │   self.model = model                                                                  │
│   31 │   │   self.model.eval()                                                                   │
│   32 │   │   if preprocessor is None:                                                            │
│                                                                                                  │
│ /opt/conda/lib/python3.7/site-packages/modelscope/models/nlp/mglm/mglm_for_text_summarization.py │
│ :371 in __init__                                                                                 │
│                                                                                                  │
│   368 │   │   # setting default batch size to 1                                                  │
│   369 │   │   self.args.batch_size = 1                                                           │
│   370 │   │   self.args.tokenizer_path = model_dir                                               │
│ ❱ 371 │   │   self.tokenizer = prepare_tokenizer(self.args)                                      │
│   372 │   │   self.model = setup_model(self.args)                                                │
│   373 │   │   self.cfg = Config.from_file(                                                       │
│   374 │   │   │   osp.join(model_dir, ModelFile.CONFIGURATION))                                  │
│                                                                                                  │
│ /opt/conda/lib/python3.7/site-packages/modelscope/models/nlp/mglm/configure_data.py:147 in       │
│ prepare_tokenizer                                                                                │
│                                                                                                  │
│   144 │   │   add_task_mask=args.task_mask,                                                      │
│   145 │   │   add_decoder_mask=args.block_mask_prob > 0.0                                        │
│   146 │   │   or args.context_mask_ratio > 0.0)                                                  │
│ ❱ 147 │   if mpu.get_model_parallel_rank() == 0:                                                 │
│   148 │   │   num_tokens = tokenizer.num_tokens                                                  │
│   149 │   │   eod_token = tokenizer.get_command('eos').Id                                        │
│   150 │   │   assert eod_token == tokenizer.get_command('pad').Id                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: module 'megatron_util.mpu' has no attribute 'get_model_parallel_rank'

During handling of the above exception, another exception occurred:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /app/test.py:11 in <module>                                                                      │
│                                                                                                  │
│    8 pipe = pipeline(                                                                            │
│    9 │   task=Tasks.text_summarization,                                                          │
│   10 │   model=model,                                                                            │
│ ❱ 11 │   preprocessor=preprocessor,                                                              │
│   12 )                                                                                           │
│   13 result = pipe(                                                                              │
│   14 │   '据中国载人航天工程办公室消息,北京时间2022年10月25日,梦天实验舱与长征五号B遥四运载    │
│                                                                                                  │
│ /opt/conda/lib/python3.7/site-packages/modelscope/pipelines/builder.py:140 in pipeline           │
│                                                                                                  │
│   137 │   if preprocessor is not None:                                                           │
│   138 │   │   cfg.preprocessor = preprocessor                                                    │
│   139 │                                                                                          │
│ ❱ 140 │   return build_pipeline(cfg, task_name=task)                                             │
│   141                                                                                            │
│   142                                                                                            │
│   143 def add_default_pipeline_info(task: str,                                                   │
│                                                                                                  │
│ /opt/conda/lib/python3.7/site-packages/modelscope/pipelines/builder.py:57 in build_pipeline      │
│                                                                                                  │
│    54 │   │   default_args (dict, optional): Default initialization arguments.                   │
│    55 │   """                                                                                    │
│    56 │   return build_from_cfg(                                                                 │
│ ❱  57 │   │   cfg, PIPELINES, group_key=task_name, default_args=default_args)                    │
│    58                                                                                            │
│    59                                                                                            │
│    60 def pipeline(task: str = None,                                                             │
│                                                                                                  │
│ /opt/conda/lib/python3.7/site-packages/modelscope/utils/registry.py:215 in build_from_cfg        │
│                                                                                                  │
│   212 │   │   │   return obj_cls(**args)                                                         │
│   213 │   except Exception as e:                                                                 │
│   214 │   │   # Normal TypeError does not print class name.                                      │
│ ❱ 215 │   │   raise type(e)(f'{obj_cls.__name__}: {e}')                                          │
│   216                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: MGLMTextSummarizationPipeline: module 'megatron_util.mpu' has no attribute 'get_model_parallel_rank'

代码内容如下:

from modelscope.models import Model
from modelscope.pipelines import pipeline
from modelscope.preprocessors import MGLMSummarizationPreprocessor
from modelscope.utils.constant import Tasks

model = 'ZhipuAI/Multilingual-GLM-Summarization-zh'
preprocessor = MGLMSummarizationPreprocessor()
pipe = pipeline(
    task=Tasks.text_summarization,
    model=model,
    preprocessor=preprocessor,
    model_revision='v1.0.1',
)
result = pipe(
    '据中国载人航天工程办公室消息,北京时间2022年10月25日,梦天实验舱与长征五号B遥四运载火箭组合体已转运至发射区。后续将按计划开展发射前各项功能检查和联合测试等工作,计划于近日择机实施发射。目前,文昌航天发射场设施设备状态良好,参试各单位正在加紧开展任务准备,全力以赴确保空间站建造任务决战决胜。'
)  
print(result)
目录
相关文章
|
3月前
|
TensorFlow API 算法框架/工具
【Tensorflow+keras】解决使用model.load_weights时报错 ‘str‘ object has no attribute ‘decode‘
python 3.6,Tensorflow 2.0,在使用Tensorflow 的keras API,加载权重模型时,报错’str’ object has no attribute ‘decode’
53 0
|
6月前
|
IDE 开发工具 Android开发
Couldn‘t get post build model. Module:UpdateService_0804.main Variant: debugOpen logcat panel fo
Couldn‘t get post build model. Module:UpdateService_0804.main Variant: debugOpen logcat panel fo
75 0
|
6月前
|
机器学习/深度学习 人工智能
【CatBoost报错解决】CatBoostError: Bad value for num feature[non default doc idx=0,feature idx=19]=
【CatBoost报错解决】CatBoostError: Bad value for num feature[non default doc idx=0,feature idx=19]=
|
11月前
问题出在`megatron_util.mpu`模块中没有找到`get_model_parallel_rank`属性
问题出在`megatron_util.mpu`模块中没有找到`get_model_parallel_rank`属性
113 1
|
API 数据格式
TensorFlow2._:model.summary() Output Shape为multiple解决方法
TensorFlow2._:model.summary() Output Shape为multiple解决方法
278 0
TensorFlow2._:model.summary() Output Shape为multiple解决方法
|
机器学习/深度学习 自然语言处理 数据挖掘
UnifiedEAE: A Multi-Format Transfer Learning Model for Event Argument Extraction via Variational论文解读
事件论元抽取(Event argument extraction, EAE)旨在从文本中抽取具有特定角色的论元,在自然语言处理中已被广泛研究。
89 0
|
机器学习/深度学习 传感器 编解码
翻译:Multi-scale Multi-path Multi-model Fusion Nerwork
M3Net: 多尺度多路径多模型融合网络及其在 RGB-D 显着目标检测中的应用实例
198 0
Re1:读论文 C&S (Correct and Smooth) Combining Label Propagation and Simple Models Out-performs Graph Ne
Re1:读论文 C&S (Correct and Smooth) Combining Label Propagation and Simple Models Out-performs Graph Ne
Re1:读论文 C&S (Correct and Smooth) Combining Label Propagation and Simple Models Out-performs Graph Ne
|
TensorFlow 算法框架/工具
TF版本升级问题:成功解决AttributeError: module tensorflow has no attribute mul
TF版本升级问题:成功解决AttributeError: module tensorflow has no attribute mul
TF版本升级问题:成功解决AttributeError: module tensorflow has no attribute mul
|
算法框架/工具 Windows

热门文章

最新文章