Skip to content

Commit 25af55c

Browse files
WhoIsYucharlesxzb
authored andcommitted
fix: set output_int16 use with float softmax only
- Change-Id: I2bd36197aed809da7d2ad032cda494a1ccd0d540
1 parent c066d32 commit 25af55c

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

lib/Conversion/TopToTpu/TopToTpuPass.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,15 +1710,22 @@ void ConvertTopToTpu::runOnOperation() {
17101710
break;
17111711
}
17121712
} else if (isa<top::SoftmaxOp>(user)) {
1713-
mlir::Attribute tmp = mlir::BoolAttr::get(op->getContext(), true);
1714-
if (module::getMode() == module::Mode::INT8 ||
1715-
module::getMode() == module::Mode::UINT8 ||
1716-
module::getMode() == module::Mode::W4INT8) {
1717-
op->setAttr("output_int16", tmp);
1718-
} else if (module::getMode() == module::Mode::F8E4M3) {
1719-
op->setAttr("output_f16", tmp);
1713+
auto name = module::getName(user).str();
1714+
if (LoweringConfig::quantize_map.find(name) !=
1715+
LoweringConfig::quantize_map.end() &&
1716+
(LoweringConfig::quantize_map[name] == module::Mode::F16 ||
1717+
LoweringConfig::quantize_map[name] == module::Mode::BF16 ||
1718+
LoweringConfig::quantize_map[name] == module::Mode::F32)) {
1719+
mlir::Attribute tmp = mlir::BoolAttr::get(op->getContext(), true);
1720+
if (module::getMode() == module::Mode::INT8 ||
1721+
module::getMode() == module::Mode::UINT8 ||
1722+
module::getMode() == module::Mode::W4INT8) {
1723+
op->setAttr("output_int16", tmp);
1724+
} else if (module::getMode() == module::Mode::F8E4M3) {
1725+
op->setAttr("output_f16", tmp);
1726+
}
1727+
break;
17201728
}
1721-
break;
17221729
}
17231730
}
17241731
}

0 commit comments

Comments
 (0)