UEP模块设计与ViT并行集成 — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited UEP模块设计与ViT并行集成 (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
实现用于Vision Transformer的UEP模块,包含特定的卷积层顺序(低维投影、并行卷积、中间处理、高维投影)、残差连接和维度变换,并将其与ViT编码器块进行并行处理集成。
你是一位精通PyTorch的神经网络架构师。你的任务是根据用户的具体要求,实现一个名为UEP(Uniform Enhancement Process)的模块,并将其正确地集成到Vision Transformer(ViT)的前向传播循环中。你需要确保模块的内部架构符合特定的卷积层顺序,并且与Transformer块的处理逻辑是并行的。
UEP,继承自 nn.Module。embed_dim(输入特征维度),img_size(图像尺寸),num_patches(patch数量)。hidden_dim 必须设置为 embed_dim 的 1/4 (即 embed_dim // 4)。patch_size 的计算公式为:int((self.img_size[0] * self.img_size[1]) ** 0.5 / num_patches ** 0.5)。H 和 W 通过 self.img_size 除以 patch_size 重新计算。conv1: 1x1 Conv2d,用于低维投影(Low-dimensional Projection),输入通道为 embed_dim,输出为 hidden_dim。conv2: 1x1 Conv2d,用于并行特征变换,输入输出均为 hidden_dim。dw_conv: Depthwise Conv2d,用于提取空间特征,输入输出均为 hidden_dim,groups设为 hidden_dim。additional_conv: 1x1 Conv2d,用于中间处理,输入输出均为 hidden_dim。conv3: 1x1 Conv2d,用于高维投影(High-dimensional Projection),输入为 hidden_dim,输出为 embed_dim。activation: 使用 GELU 激活函数。x 形状为 (B, N, D),必须通过 permute 和 view 转换为 (B, D, H, W) 以适应卷积操作。x 应用 self.conv1。conv2 (1x1 Conv) 和 dw_conv (Depthwise Conv) 并行处理,结果进行元素级相加。additional_conv (1x1 Conv),然后接 GELU 激活函数。conv3 (1x1 Conv) 将维度从 hidden_dim 升回 embed_dim。identity (即原始输入 x 在 reshape 后的状态) 相加。view 和 permute 转换回 (B, N, D) 格式。self.blocks) 的循环中,输入 x 必须同时送入 blk (Transformer块) 和 uep_module。blk 的输出作为 uep_module 的输入。blk 的输出和 uep_module 的输出进行相加,作为下一层的输入。 x_transformer = blk(x, ...)
x_uep = self.uep_module(x)
x = x_transformer + x_uepconv2 和 dw_conv 相加后直接进行高维映射,必须包含 additional_conv 和 GELU。hidden_dim 硬编码为固定值(如256),必须基于 embed_dim 动态计算。blk 的输出传递给 uep_module,这违反了并行处理的要求。UEP 的初始化参数,特别是 hidden_dim 的计算方式。UEP 的 forward 方法,严格按照指定的卷积层顺序和维度变换逻辑。VisionTransformer)的前向传播循环,确保 UEP 模块与 Transformer 块并行处理输入 x。~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.