MCPcopy Create free account
hub / github.com/MotrixLab/insactor / ReMoDiffuseTransformer

Class ReMoDiffuseTransformer

diffplanner/models/transformers/remodiffuse.py:170–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168
169@SUBMODULES.register_module()
170class ReMoDiffuseTransformer(DiffusionTransformer):
171 def __init__(self, guide_scale=None, retr_guide_scale=None, retrieval_cfg=None, waypoint=False, **kwargs):
172 super().__init__(**kwargs)
173 self.guide_scale = guide_scale
174 self.retr_guide_scale = retr_guide_scale
175 self.waypoint = waypoint
176 if retrieval_cfg is None:
177 self.use_retrieval = False
178 else:
179 self.database = RetrievalDatabase(**retrieval_cfg)
180 self.use_retrieval = True
181
182 def get_precompute_condition(self, text=None, motion_length=None, xf_out=None, re_feat=None, device=None):
183 if xf_out is None:
184 xf_out = self.encode_text(text, device)
185 output = {'xf_out': xf_out}
186 if self.use_retrieval:
187 if re_feat is None:
188 re_feat = self.database(text, motion_length, self.clip, device)
189 output['re_feat'] = re_feat
190 return output
191
192 def forward_train(self, h=None, src_mask=None, emb=None, xf_out=None, re_feat=None, **kwargs):
193 B, T = h.shape[0], h.shape[1]
194 cond_type = random.randint(0, 99)
195 for module in self.temporal_decoder_blocks:
196 h = module(x=h, xf=xf_out, emb=emb, src_mask=src_mask, cond_type=cond_type, re_feat=re_feat)
197
198 output = self.out(h).view(B, T, -1).contiguous()
199 return output
200
201 def forward_test(self, h=None, src_mask=None, emb=None, xf_out=None, re_feat=None, **kwargs):
202 B, T = h.shape[0], h.shape[1]
203 scale = self.guide_scale
204
205 # for waypoint heading
206 if self.waypoint:
207 src_mask = src_mask * 0 + 1
208
209 # # for unconditional
210 # cond_type = 0
211 # for module in self.temporal_decoder_blocks:
212 # h = module(x=h, xf=xf_out, emb=emb, src_mask=src_mask, cond_type=cond_type, re_feat=re_feat)
213 # output = self.out(h).view(B, T, -1).contiguous()
214 # return output
215
216 if abs(scale - 1.0) < 0.000001:
217 cond_type = 99
218 for module in self.temporal_decoder_blocks:
219 h = module(x=h, xf=xf_out, emb=emb, src_mask=src_mask, cond_type=cond_type, re_feat=re_feat)
220 output = self.out(h).view(B, T, -1).contiguous()
221 elif not self.use_retrieval:
222 h0 = h
223 cond_type = 0
224 for module in self.temporal_decoder_blocks:
225 h0 = module(x=h0, xf=xf_out, emb=emb, src_mask=src_mask, cond_type=cond_type, re_feat=re_feat)
226 out0 = self.out(h0).view(B, T, -1).contiguous()
227 h1 = h

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected