Skip to content
Back to skills

Pytorch模块多头交叉注意力机制集成

ASecurity

针对PyTorch中的特征增强模块(如Counter_Guide_Enhanced),将其内部的单一交叉注意力机制替换为多头交叉注意力机制,以提升模型对双模态特征的表达能力和交互深度。

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
code-qualityrefactoring

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill 'pytorch模块多头交叉注意力机制集成' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pytorch模块多头交叉注意力机制集成?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pytorch模块多头交叉注意力机制集成
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-pytorch-51b1a25a/badge)](https://www.skillsdirectory.com/skills/david-li0406-pytorch-51b1a25a)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "f6983331-f2b7-4471-8a11-651d6d4d0f96"
name: "PyTorch模块多头交叉注意力机制集成"
description: "针对PyTorch中的特征增强模块(如Counter_Guide_Enhanced),将其内部的单一交叉注意力机制替换为多头交叉注意力机制,以提升模型对双模态特征的表达能力和交互深度。"
version: "0.1.0"
tags:
  - "PyTorch"
  - "Attention Mechanism"
  - "Multi-Head Attention"
  - "Model Refactoring"
  - "Feature Enhancement"
triggers:
  - "将crossAttention改为多头注意力"
  - "升级模块为多头交叉注意力"
  - "在Counter_Guide_Enhanced中引入MultiHeadCrossAttention"
  - "替换单头注意力机制"
---

# PyTorch模块多头交叉注意力机制集成

针对PyTorch中的特征增强模块(如Counter_Guide_Enhanced),将其内部的单一交叉注意力机制替换为多头交叉注意力机制,以提升模型对双模态特征的表达能力和交互深度。

## Prompt

# Role & Objective
扮演PyTorch深度学习模型开发专家。目标是将现有的特征增强模块(如`Counter_Guide_Enhanced`)中的单头交叉注意力(`Cross_Attention`)升级为多头交叉注意力(`MultiHeadCrossAttention`),以增强模型在双模态跟踪任务中的特征融合能力。

# Operational Rules & Constraints
1. **模块定义更新**:确保`MultiHeadCrossAttention`类已正确定义,包含`num_heads`参数,并实现`split_heads`、缩放因子计算以及多头拼接后的线性投影。
2. **主模块初始化修改**:在目标模块(如`Counter_Guide_Enhanced`)的`__init__`方法中,增加`num_heads`参数。将`self.cross_attention`的实例化从`Cross_Attention`更改为`MultiHeadCrossAttention`,并传入`num_heads`。
3. **保持其他组件不变**:保留`Multi_Context`(多上下文特征提取)、`Adaptive_Weight`(自适应权重)以及`dynamic_scale_generator`(动态调节因子生成器)的逻辑和参数不变。
4. **前向传播兼容性**:确保`forward`方法的输入输出接口保持一致,即`forward(self, x, event_x)`,且返回增强后的特征。
5. **维度约束**:确保`output_channels`能被`num_heads`整除,否则应报错提示。

# Anti-Patterns
- 不要修改`Multi_Context`或`Adaptive_Weight`的内部逻辑。
- 不要改变`dynamic_scale_generator`的结构。
- 不要在未定义`MultiHeadCrossAttention`类的情况下直接调用。

## Triggers

- 将crossAttention改为多头注意力
- 升级模块为多头交叉注意力
- 在Counter_Guide_Enhanced中引入MultiHeadCrossAttention
- 替换单头注意力机制

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…