举例:在I2VGen-XL的推理环境安装中,如果安装了2.24.0以后版本的 open_clip_torch
,那么这些版本中的Transformer具有默认的 batch_first=True
参数,特别是在函数调用中很难找到如何在传递中增加这个变更后的参数。
这可能导致出现如下报错:
Exception: Failed to invoke function <function inference_i2vgen_entrance at 0x7f5e6f958c10>, with The shape of the 2D attn_mask is torch.Size([77, 77]), but should be (1, 1).
解决方案其实可以直接参考open_clip_torch的变更方法,即:
对于VGen来说,就是注释图中的两行对x的变换。源代码位于Github/VGen/tools/modules/clip_embedder.py
更通用的方法是改成
```py
def encode_with_transformer(self, text):
x = self.model.token_embedding(text) # [batch_size, n_ctx, d_model]
x = x + self.model.positional_embedding
if version.parse(open_clip.__version__) LND
x = self.text_transformer_forward(x, attn_mask=self.model.attn_mask)
if version.parse(open_clip.__version__) NLD
x = self.model.ln_final(x)
return x
```