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

Function get_rolling_token_windows

test/general/lm_eval/utils.py:135–173  ·  view source on GitHub ↗

- context_len allows for a rolling window context, allowing each prediction window to potentially condition on some context :param token_list: list List of tokens to be PREDICTED :param max_seq_len: int max_seq_len of model (or max_seq_len we want to use) :par

(token_list, prefix_token, max_seq_len, context_len)

Source from the content-addressed store, hash-verified

133
134
135def get_rolling_token_windows(token_list, prefix_token, max_seq_len, context_len):
136 """
137 - context_len allows for a rolling window context, allowing each prediction window to potentially
138 condition on some context
139
140 :param token_list: list
141 List of tokens to be PREDICTED
142 :param max_seq_len: int
143 max_seq_len of model (or max_seq_len we want to use)
144 :param context_len: int
145 Amount of desired token context for prediction. Needs to be at least 1.
146 :param prefix_token: token
147 Dummy token like <eos> so the first token has something to condition on
148 :return: generator
149 Generator of tuples
150 (input_tokens, pred_tokens)
151 Note: Score only the last len(pred_tokens) logits of the LM
152 """
153 assert 1 <= context_len <= max_seq_len
154 if not token_list:
155 return
156 # +1 offset, going from input->preds
157 pred_len = max_seq_len - context_len + 1
158 predicted = 0
159
160 # Special handling for first window: predict all tokens
161 first_seq_len = min(max_seq_len, len(token_list))
162 yield ([prefix_token] + token_list[: first_seq_len - 1], token_list[:first_seq_len])
163 predicted += first_seq_len
164
165 while predicted < len(token_list):
166 window_pred_len = min(len(token_list) - predicted, pred_len)
167 window_end = predicted + window_pred_len
168
169 yield (
170 token_list[window_end - max_seq_len - 1 : window_end - 1],
171 token_list[window_end - window_pred_len : window_end],
172 )
173 predicted += window_pred_len
174
175
176def make_disjoint_window(pair):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected