Skip to content

Conversation

@Lyu6PosHao
Copy link

@Lyu6PosHao Lyu6PosHao commented Dec 3, 2025

描述 (Description)

修改ROPE算子,添加对VISION模式的支持。

测试 (Testing)

依照如下步骤进行测试,首先,在入口处修改判断条件。采取短路设置,确保mode为VISION模式时必然能够调用算子进行计算;其他判断条件保持不变。

case GGML_OP_ROPE: {
            // TODO: with ops-test v == 1
            float ext_factor = 0.0f;
            memcpy(&ext_factor, (const float *) op->op_params + 7, sizeof(float));
            const int mode = ((const int32_t *) op->op_params)[2];
            const bool is_mrope = mode & GGML_ROPE_TYPE_MROPE;
            const bool is_vision = mode == GGML_ROPE_TYPE_VISION;
            //printf("[DEBUG] ROPE mode=%d is_mrope=%d is_vision=%d ext_factor=%f\n", mode, is_mrope, is_vision,ext_factor);
            fflush(stdout);

            if (is_vision) {
            //printf("[DEBUG] Accepting VISION ROPE (mode=%d)\n", mode);
            fflush(stdout);
                return true;
            }

            // TODO: n_dims <= ne0
            if (op->src[0]->ne[0] != op->op_params[1]) {
                //printf("[DEBUG] Rejected: Dim mismatch a=%d b=%d\n",op->src[0]->ne[0],op->op_params[1]);
                return false;
            }
            // TODO: ext_factor != 0
            if (ext_factor != 0) {
                //printf("[DEBUG] Rejected: ext_factor is not 0\n");
                return false;
            }

            if (is_mrope && !is_vision) {
                //printf("[DEBUG] Accepting MROPE (mode=%d)\n", mode);
                return false;
            }
            

            if(!ggml_is_contiguous(op->src[0])){
                return false;
            }
            return true;
        }

进行编译并测试:

cmake -B build -DGGML_CANN=on -DCMAKE_BUILD_TYPE=release
cmake --build build --config release -j
./build/bin/test-backend-ops test -b CANN0 -o ROPE

最终的运行如下图所示。使用红色方框标记出了mode=24(即VISION模式)的测试用例。如下:
ea50dbfc1bb30b914671057f577c2bae

备注 (Notes)

此代码参考了社区最新更新的ROPE的部分函数(https://github.com/ggml-org/llama.cpp)

@Lyu6PosHao Lyu6PosHao changed the title ROPE算子:VISION模式支持 CANN: ROPE VISION Dec 3, 2025
@Lyu6PosHao Lyu6PosHao changed the title CANN: ROPE VISION CANN: Support ROPE_VISION Dec 3, 2025
@noemotiovon
Copy link
Owner

非常感谢你的贡献,如果对于社区当前的ROPE实现有优化的,也非常欢迎贡献到上游社区!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants