)for_inrange(self.depth)# 循环生成每个 Transformer 块]# 根据是否使用线性投影选择输出层ifself.use_linear_projection:# 创建一个线性投影层,输出维度为 inner_dim,数据类型为 self.dtypeself.proj_out = nn.Dense(inner_dim, dtype=self.dtype)else:# 创建一个卷积层,输出维度为 inner_dim,卷积核大小为 ...
self.proj_in = torch.nn.Linear(self.in_channels, self.inner_dim)# 否则,创建卷积层进行输入投影else: self.proj_in = torch.nn.Conv2d(self.in_channels, self.inner_dim, kernel_size=1, stride=1, padding=0)# 创建变换器块的模块列表self.transformer_blocks = nn.ModuleList([# 对于每一层,初始...
🤗 Diffusers: State-of-the-art diffusion models for image, video, and audio generation in PyTorch and FLAX. - diffusers/src/diffusers/models/attention.py at main · huggingface/diffusers
self.inner_dim)))self.controlnet_x_embedder=torch.nn.Linear(in_channels,self.inner_dim,bias=True)self.gradient_checkpointing=False@property# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel
(torch.float32)).to(emb.dtype))# 计算偏移量x= self.norm(x) + shift.unsqueeze(dim=1)# 对输入进行归一化并加上偏移returnx# 返回处理后的张量@maybe_allow_in_graph# 装饰器,可能允许在计算图中使用class HunyuanDiTBlock(nn.Module):# 定义 Hunyuan-DiT 模型中的变换器块类r""" # 类文档字符...
in_channels (`int`): The number of channels in the input. # 第一层 conv2d 的输出通道数量,默认为 None 表示与输入通道相同 out_channels (`int`, *optional*, default to be `None`): The number of output channels for the first conv2d layer. If None, same as `in_channels`. ...
( # Calls into the C++ engine to run the bac ││ 201 │ │ tensors, grad_tensors_, retain_graph, create_graph, inputs, ││ 202 │ │ allow_unreachable=True, accumulate_grad=True) # Calls into the C++ engine to ru ││ 203 │╰─────────────────────...
use_safetensors =Trueallow_pickle =True# 设置用户代理信息,用于标识请求的类型和框架user_agent = {"file_type":"text_inversion","framework":"pytorch", }# 初始化状态字典列表state_dicts = []# 遍历预训练模型名称或路径列表forpretrained_model_name_or_pathinpretrained_model_name_or_paths:# 检查当...