OpenBMB / MiniCPM

MiniCPM-2B: An end-side LLM outperforming Llama2-13B.
Apache License 2.0
4.66k stars 334 forks source link

[Bug]:关于 mlc-MiniCPM 编译过程中发生的几个异常 #69

Closed icecoins closed 6 months ago

icecoins commented 6 months ago

Is there an existing issue ? / 是否已有相关的 issue ?

Describe the bug / 描述这个 bug

量化、编译时发生的异常

  1. TVMError: Check failed: (_len != nullptr) is false: Reshape only expects the input new shape to be either an Expr or an Array of PrimExprs. However, the given new shape is [[1, 1152, 1, 1]]

  2. AttributeError: <class 'tvm.tir.expr.Mul'> has no attribute value.

  3. python缺少tqdm、timm、SentencePiece库

To Reproduce / 如何复现

1.对于MiniCPM-V,在按步骤 [ https://github.com/OpenBMB/mlc-MiniCPM/blob/main/README-ZH.md ] 执行至

mlc_chat convert_weight --model-type ${MODEL_TYPE} ./dist/models/${MODEL_NAME}-hf/ --quantization $QUANTIZATION -o dist/$MODEL_NAME/

时,引发

TVMError: Check failed: (_len != nullptr) is false: Reshape only expects the input new shape to be either an Expr or an Array of PrimExprs. However, the given new shape is [[1, 1152, 1, 1]]

2.对于MiniCPM和MiniCPM-V,在按步骤执行至

mlc_chat compile --model-type ${MODEL_TYPE} dist/${MODEL_NAME}/mlc-chat-config.json --device android -o ./dist/libs/${MODEL_NAME}-android.tar

时,引发

AttributeError: <class 'tvm.tir.expr.Mul'> has no attribute value.

3.同上条件及步骤,引发python缺库

Expected behavior / 期望的结果

我希望将这些相关事项写在 [ https://github.com/OpenBMB/mlc-MiniCPM/ ] 的文档里或以其他方式直接修复(因为我在租用云端显卡进行编译时需要多次重复地自行修改代码,深感麻烦)

1.需要修改py文件,位于

...env/python/tvm/relax/frontend/nn/_tensor_op.py
line 81-85

引用 https://github.com/OpenBMB/MiniCPM/issues/47

    def reshape(self, *shape):
        return _op().reshape(self, shape)

    def permute_dims(self, *axes):
        return _op().permute_dims(self, axes)

我将其改为

    def reshape(self, shape):
        return _op().reshape(self, shape)

    def permute_dims(self, axes):
        return _op().permute_dims(self, axes)

2.需要修改py文件,位于

  .../mlc-MiniCPM/python/mlc_chat/compiler_pass/estimate_memory_usage.py,
line 83

引用 https://github.com/OpenBMB/mlc-MiniCPM/pull/2

    def _storage_alloc(self, size: relax.Expr) -> None:
        assert isinstance(size, relax.ShapeExpr)
        self.planned_mem_num += 1
        self.planned_alloc_mem += size.values[0].value

我将其改为

    def _storage_alloc(self, size: relax.Expr) -> None:
        assert isinstance(size, relax.ShapeExpr)
        if hasattr(size.values[0], 'value'):
            self.planned_mem_num += 1
            self.planned_alloc_mem += size.values[0].value

或参考https://github.com/mlc-ai/mlc-llm/blob/main/python/mlc_chat/compiler_pass/estimate_memory_usage.py

    def _storage_alloc(self, size: relax.Expr) -> None:
        assert isinstance(size, relax.ShapeExpr)
        if isinstance(size.values[0], tir.IntImm):
            self.planned_mem_num += 1
            self.planned_alloc_mem += size.values[0].value

3.安装conda环境时需要附带地

pip install tqdm timm sentencepiece

仅为提醒,如有错漏还请指出

Screenshots / 截图

Environment / 环境

- OS: [Ubuntu 22.04]
- Pytorch: [torch 2.0.0]
- CUDA: [CUDA 11.8]
- Device: [gtx 1660ti]

Additional context / 其他信息

Achazwl commented 6 months ago

Due to the continuous updates of the original MLC-LLM repo, these changes you have made are recent updates of MLC-LLM. We plan to merge into MLC-LLM so that these modifications will not happen.

icecoins commented 6 months ago

thx