MCPcopy Create free account
hub / github.com/Monalissaa/DisenDiff / update_alpha_time_word

Function update_alpha_time_word

src/ptp_utils.py:265–275  ·  view source on GitHub ↗
(alpha, bounds: Union[float, Tuple[float, float]], prompt_ind: int,
                           word_inds: Optional[torch.Tensor]=None)

Source from the content-addressed store, hash-verified

263
264
265def update_alpha_time_word(alpha, bounds: Union[float, Tuple[float, float]], prompt_ind: int,
266 word_inds: Optional[torch.Tensor]=None):
267 if type(bounds) is float:
268 bounds = 0, bounds
269 start, end = int(bounds[0] * alpha.shape[0]), int(bounds[1] * alpha.shape[0])
270 if word_inds is None:
271 word_inds = torch.arange(alpha.shape[2])
272 alpha[: start, prompt_ind, word_inds] = 0
273 alpha[start: end, prompt_ind, word_inds] = 1
274 alpha[end:, prompt_ind, word_inds] = 0
275 return alpha
276
277
278def get_time_words_attention_alpha(prompts, num_steps,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected