Skip to content

[DIPU] 关于linear custom_fallback导致的错误。 #593

@Reinerzhou

Description

@Reinerzhou

背景

dipu对有针对部分算子的 custom_fallback 逻辑。

问题描述

在这个commit将linear的custom_fallback设为true之后。

- schema: "linear(Tensor input, Tensor weight, Tensor? bias=None) -> Tensor"
custom_fallback: True

在燧原以及华为上运行llama_finetune时会有如下报错:
image

问题分析

由于dipu存在自定义的dispatch逻辑(包括custom_fallback),影响了dynamo中对meta key的dispatch行为,在linear设为custom_fallback后,会影响linear_backward的dispatch行为:
image(1)

改进建议

custom_fallback的逻辑主要在这里:

#define DIOPI_ATEN_FUNC_CUSTOM_FALLBACK(opname, diopi_func, force_fallback, \
wapper_func, custom_fallback_func) \
do { \
if ((reinterpret_cast<void*>(diopi_func) != nullptr) && \
!((force_fallback) || dipu::get_force_fallback(opname))) { \
m.impl(opname, TORCH_FN(wapper_func)); \
} else { \
if ((reinterpret_cast<void*>(diopi_func) == nullptr)) { \
DIPU_OP_LOG_WARNING_ONCE(#diopi_func << " is not yet implemented, "); \
} else { \
DIPU_OP_LOG_WARNING_ONCE("force fallback has been set, "); \
} \
DIPU_OP_LOG_WARNING_ONCE((opname) << " will be fallback to cpu" \
<< "\n"); \
m.impl(opname, TORCH_FN(custom_fallback_func)); \
} \
} while (false);

通过增设一个环境变量DIPU_DISABLE_CUSTOM_FALLBACK以及disable_custom_fallback_ops_list在必要时禁用custom_fallback的逻辑(默认开启custom_fallback)。

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