MCPcopy Create free account
hub / github.com/THUDM/GLM / BeamScorer

Class BeamScorer

generation_utils.py:112–138  ·  view source on GitHub ↗

Abstract base class for all beam scorers that are used for :meth:`~transformers.PretrainedModel.beam_search` and :meth:`~transformers.PretrainedModel.beam_sample`.

Source from the content-addressed store, hash-verified

110
111
112class BeamScorer(ABC):
113 """
114 Abstract base class for all beam scorers that are used for :meth:`~transformers.PretrainedModel.beam_search` and
115 :meth:`~transformers.PretrainedModel.beam_sample`.
116 """
117
118 @abstractmethod
119 def process(
120 self,
121 input_ids: torch.LongTensor,
122 next_scores: torch.FloatTensor,
123 next_tokens: torch.LongTensor,
124 next_indices: torch.LongTensor,
125 **kwargs
126 ) -> Tuple[torch.Tensor]:
127 raise NotImplementedError("This is an abstract method.")
128
129 @abstractmethod
130 def finalize(
131 self,
132 input_ids: torch.LongTensor,
133 next_scores: torch.FloatTensor,
134 next_tokens: torch.LongTensor,
135 next_indices: torch.LongTensor,
136 **kwargs
137 ) -> torch.LongTensor:
138 raise NotImplementedError("This is an abstract method.")
139
140
141class BeamSearchScorer(BeamScorer):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected