MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / _model_call

Method _model_call

test/general/utils_eval.py:76–105  ·  view source on GitHub ↗

inps: a torch tensor of shape [batch, sequence] the size of sequence may vary from call to call returns: a torch tensor of shape [batch, sequence, vocab] with the logits returned from the model

(self, inps)

Source from the content-addressed store, hash-verified

74 return self.tokenizer.decode(tokens)
75
76 def _model_call(self, inps):
77 """
78 inps: a torch tensor of shape [batch, sequence]
79 the size of sequence may vary from call to call
80
81 returns: a torch tensor of shape [batch, sequence, vocab] with the
82 logits returned from the model
83 """
84 with torch.no_grad():
85 if isinstance(self.model, transformers.models.t5.modeling_t5.T5ForConditionalGeneration):
86 dec_inps = torch.cat(
87 [
88 torch.tensor(
89 self.model.generation_config.decoder_start_token_id,
90 )
91 .tile(len(inps), 1)
92 .to(inps),
93 inps,
94 ],
95 dim=1,
96 )
97
98 kwargs = {"decoder_input_ids": dec_inps,}
99 else:
100 kwargs = {}
101 out = self.model(inps, **kwargs)[0]
102 if "opt" in self.model_name: # there are a few extra tokens in opt, which we should omit
103 return out[:, :, :50257]
104 else:
105 return out # [:, :, :self.tokenizer.vocab_size]
106
107 def _model_generate(self, context, max_length, eos_token_id):
108 return self.model.generate(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected