Initial commit
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
ops_shim.py — ComfyUI `comfy.ops.disable_weight_init` 的独立替身。
|
||||
|
||||
VOSR2 模型代码(LightningDiT / DINOv2 / Qwen-VAE)只用到了
|
||||
ops.Conv2d / ops.Linear / ops.LayerNorm,语义与 torch.nn 完全一致,
|
||||
唯一区别是跳过权重初始化(加载 checkpoint 前无需初始化,省时且结果确定)。
|
||||
这里提供一个覆盖常用层类型的等价实现,不依赖 ComfyUI。
|
||||
"""
|
||||
import torch.nn as nn
|
||||
|
||||
|
||||
class disable_weight_init:
|
||||
"""与 comfy.ops.disable_weight_init 等价:各层类型跳过 reset_parameters。"""
|
||||
|
||||
class Linear(nn.Linear):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class Conv1d(nn.Conv1d):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class Conv2d(nn.Conv2d):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class Conv3d(nn.Conv3d):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class ConvTranspose1d(nn.ConvTranspose1d):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class ConvTranspose2d(nn.ConvTranspose2d):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class ConvTranspose3d(nn.ConvTranspose3d):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class LayerNorm(nn.LayerNorm):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class GroupNorm(nn.GroupNorm):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class BatchNorm2d(nn.BatchNorm2d):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
|
||||
class Embedding(nn.Embedding):
|
||||
def reset_parameters(self):
|
||||
return None
|
||||
Reference in New Issue
Block a user