MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / make_time_attn

Function make_time_attn

sat/sgm/modules/autoencoding/temporal_ae.py:240–271  ·  view source on GitHub ↗
(
    in_channels,
    attn_type="vanilla",
    attn_kwargs=None,
    alpha: float = 0,
    merge_strategy: str = "learned",
)

Source from the content-addressed store, hash-verified

238
239
240def make_time_attn(
241 in_channels,
242 attn_type="vanilla",
243 attn_kwargs=None,
244 alpha: float = 0,
245 merge_strategy: str = "learned",
246):
247 assert attn_type in [
248 "vanilla",
249 "vanilla-xformers",
250 ], f"attn_type {attn_type} not supported for spatio-temporal attention"
251 print(f"making spatial and temporal attention of type '{attn_type}' with {in_channels} in_channels")
252 if not XFORMERS_IS_AVAILABLE and attn_type == "vanilla-xformers":
253 print(
254 f"Attention mode '{attn_type}' is not available. Falling back to vanilla attention. "
255 f"This is not a problem in Pytorch >= 2.0. FYI, you are running with PyTorch version {torch.__version__}"
256 )
257 attn_type = "vanilla"
258
259 if attn_type == "vanilla":
260 assert attn_kwargs is None
261 return partialclass(VideoBlock, in_channels, alpha=alpha, merge_strategy=merge_strategy)
262 elif attn_type == "vanilla-xformers":
263 print(f"building MemoryEfficientAttnBlock with {in_channels} in_channels...")
264 return partialclass(
265 MemoryEfficientVideoBlock,
266 in_channels,
267 alpha=alpha,
268 merge_strategy=merge_strategy,
269 )
270 else:
271 return NotImplementedError()
272
273
274class Conv2DWrapper(torch.nn.Conv2d):

Callers

nothing calls this directly

Calls 2

partialclassFunction · 0.90
printFunction · 0.50

Tested by

no test coverage detected