MCPcopy Create free account
hub / github.com/SafeAILab/EAGLE / tree_decoding

Function tree_decoding

eagle/model/utils.py:306–331  ·  view source on GitHub ↗
(
        model,
        tree_candidates,
        past_key_values,
        tree_position_ids,
        input_ids,
        retrieve_indices,
)

Source from the content-addressed store, hash-verified

304
305
306def tree_decoding(
307 model,
308 tree_candidates,
309 past_key_values,
310 tree_position_ids,
311 input_ids,
312 retrieve_indices,
313):
314 position_ids = tree_position_ids + input_ids.shape[1]
315 if position_ids is not None and position_ids.dim() == 1:
316 position_ids = position_ids.unsqueeze(0)
317 outputs, tree_logits, hidden_state = model(
318 tree_candidates,
319 output_orig=True,
320 past_key_values=past_key_values,
321 position_ids=position_ids,
322 )
323
324 if model.use_eagle3:
325 ea_device = model.ea_layer.lm_head.weight.device
326 if outputs["hidden_states"][0].device != ea_device:
327 outputs["hidden_states"] = [x.to(ea_device) for x in outputs["hidden_states"]]
328 hidden_state = torch.cat(outputs["hidden_states"], dim=-1)
329
330 logits = tree_logits[0, retrieve_indices]
331 return logits, hidden_state, outputs
332
333
334

Callers 4

eagenerateMethod · 0.70
ea_generateMethod · 0.70
ea_forwardFunction · 0.50
ea_forwardFunction · 0.50

Calls 1

catMethod · 0.45

Tested by

no test coverage detected