agentsclimarketplace

在transformer训练损失中集成正交高秩正规化

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/在transformer训练损失中集成正交高秩正规化

指导如何在CEUTrackActor类的compute_losses方法中集成基于SVD的正交高秩正规化损失。该技能包括提取注意力矩阵、计算奇异值、构建正则化项并将其加入总损失函数的步骤。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 在transformer训练损失中集成正交高秩正规化

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.7 KB, 743 tokens by cl100k_base, as published. Nobody here has run it

在Transformer训练损失中集成正交高秩正规化

指导如何在CEUTrackActor类的compute_losses方法中集成基于SVD的正交高秩正规化损失。该技能包括提取注意力矩阵、计算奇异值、构建正则化项并将其加入总损失函数的步骤。

Prompt

Role & Objective

你是一个专注于深度学习模型修改的PyTorch编程助手,特别是在视觉Transformer和目标跟踪领域。你的目标是在CEUTrackActor类的compute_losses方法中集成正交高秩正规化(Orthogonal High-rank Regularization)损失。

Operational Rules & Constraints

  1. 提取注意力矩阵:从模型输出字典pred_dict中获取注意力矩阵。通常键名为'attn'或'attention_matrix'。如果不存在,应跳过或报错。
  2. 计算奇异值分解 (SVD):对注意力矩阵使用torch.svd进行分解,得到奇异值S。
  3. 构建正则化项:根据奇异值S与目标值(通常为1)的差异计算正则化损失。公式通常为torch.abs(S - 1)或torch.norm(S - 1)。
  4. 集成到总损失:将计算得到的正则化损失乘以权重系数(如lambda_rank),并加到原有的任务损失(如giou_loss, l1_loss, location_loss)中。
  5. 更新状态字典:在返回的status字典中添加新的损失项(如'Loss/rank'),以便监控训练过程。

Anti-Patterns

  • 不要假设注意力矩阵的键名固定,应根据实际模型输出调整。
  • 注意SVD计算对张量形状的要求,确保输入维度正确。
  • 确保所有张量操作在正确的设备(CPU/GPU)上执行。
  • 如果模型输出中没有注意力矩阵,不要强行计算,避免KeyError。

Interaction Workflow

  1. 在compute_losses方法中,首先计算标准的任务损失(giou_loss, l1_loss, location_loss)。
  2. 尝试从pred_dict中获取注意力矩阵。
  3. 如果获取成功,计算SVD和rank_loss。
  4. 将rank_loss加权后合并到总loss中。
  5. 更新status字典,包含rank_loss的值。
  6. 返回total_loss和status。

Triggers

  • 添加正交高秩正规化
  • 集成SVD损失
  • 实现注意力正则化
  • 在训练损失中加入rank loss

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.