@@ -167,26 +167,7 @@ infinilm::runtime::Tensor Qwen35Attention::forward_static_(const infinilm::runti
167167 auto v_reshaped = v->view ({batch_size, seq_len, num_key_value_heads_, head_dim_});
168168
169169 auto attn_output = attn_->forward (q_reshaped, k_reshaped, v_reshaped, forward_context);
170- {
171- const auto ops_other = [&]() {
172- auto ops_output = infinilm::runtime::Tensor::empty (runtime, gate->shape (), gate->dtype ());
173- INFINILM_ASSERT (runtime.device ().type () != infinilm::runtime::Device::Type::kCpu
174- && runtime.device ().type () != infinilm::runtime::Device::Type::kMars
175- && runtime.device ().type () != infinilm::runtime::Device::Type::kThead );
176- infinilm::execution::submit<infini::ops::Sigmoid>(
177- runtime, infini::ops::Sigmoid::DefaultConfig (runtime.device ().type ()), gate, ops_output);
178- INFINILM_TRACE_OP (Sigmoid, ops_output);
179- return ops_output;
180- }()->view (attn_output->shape ());
181- auto ops_output = infinilm::runtime::Tensor::empty (runtime, attn_output->shape (), attn_output->dtype ());
182- INFINILM_ASSERT (runtime.device ().type () != infinilm::runtime::Device::Type::kCpu
183- && runtime.device ().type () != infinilm::runtime::Device::Type::kMars
184- && runtime.device ().type () != infinilm::runtime::Device::Type::kThead );
185- infinilm::execution::submit<infini::ops::Mul>(
186- runtime, infini::ops::Mul::DefaultConfig (runtime.device ().type ()), attn_output, ops_other, ops_output);
187- INFINILM_TRACE_OP (Mul, ops_output);
188- attn_output = std::move (ops_output);
189- }
170+ infinilm::layers::attention::detail::apply_output_gate (runtime, attn_output, gate, true );
190171 return o_proj_->forward (runtime, attn_output);
191172}
192173
@@ -209,26 +190,7 @@ infinilm::runtime::Tensor Qwen35Attention::forward_paged_(const infinilm::runtim
209190 std::tie (q_reshaped, k_reshaped) = mrope_->forward (runtime, q_reshaped, k_reshaped, position_ids);
210191
211192 auto attn_output = attn_->forward (q_reshaped, k_reshaped, v_reshaped, forward_context);
212- {
213- const auto ops_other = [&]() {
214- auto ops_output = infinilm::runtime::Tensor::empty (runtime, gate->shape (), gate->dtype ());
215- INFINILM_ASSERT (runtime.device ().type () != infinilm::runtime::Device::Type::kCpu
216- && runtime.device ().type () != infinilm::runtime::Device::Type::kMars
217- && runtime.device ().type () != infinilm::runtime::Device::Type::kThead );
218- infinilm::execution::submit<infini::ops::Sigmoid>(
219- runtime, infini::ops::Sigmoid::DefaultConfig (runtime.device ().type ()), gate, ops_output);
220- INFINILM_TRACE_OP (Sigmoid, ops_output);
221- return ops_output;
222- }()->view (attn_output->shape ());
223- auto ops_output = infinilm::runtime::Tensor::empty (runtime, attn_output->shape (), attn_output->dtype ());
224- INFINILM_ASSERT (runtime.device ().type () != infinilm::runtime::Device::Type::kCpu
225- && runtime.device ().type () != infinilm::runtime::Device::Type::kMars
226- && runtime.device ().type () != infinilm::runtime::Device::Type::kThead );
227- infinilm::execution::submit<infini::ops::Mul>(
228- runtime, infini::ops::Mul::DefaultConfig (runtime.device ().type ()), attn_output, ops_other, ops_output);
229- INFINILM_TRACE_OP (Mul, ops_output);
230- attn_output = std::move (ops_output);
231- }
193+ infinilm::layers::attention::detail::apply_output_gate (runtime, attn_output, gate, true );
232194 return o_proj_->forward (runtime, attn_output);
233195}
234196} // namespace infinilm::models::qwen3_5
0 commit comments