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

Method loglikelihood_rolling

test/general/lm_eval/base.py:50–89  ·  view source on GitHub ↗

Compute full log-likelihood of a string, with no truncation, for perplexity computation - We will use the full max context length of the model. - For inputs that exceed the max context length, we divide the tokenized string into chunks of up to the max context length.

(self, requests)

Source from the content-addressed store, hash-verified

48
49 @abstractmethod
50 def loglikelihood_rolling(self, requests):
51 """Compute full log-likelihood of a string, with no truncation, for perplexity computation
52 - We will use the full max context length of the model.
53 - For inputs that exceed the max context length, we divide the tokenized string into chunks of up to
54 the max context length.
55 - IMPORTANT: Each document's loglikelihood/perplexity is computed *separately*, unlike other implementations
56 which may simply concatenate multiple documents together.
57 - IMPORTANT: We maximize the amount of context for each prediction. Specifically, for inputs that we break into
58 multiple chunks, the last input will still a full-sized context.
59 Example:
60 Input tokens: [ 0 1 2 3 4 5 6 7 8 9 ]
61 Prefix: EOT
62 Max context length: 4
63 Resulting input/prediction pairs:
64
65 INPUT: EOT 0 1 2
66 PRED: 0 1 2 3
67
68 INPUT: 3 4 5 6
69 PRED: 4 5 6 7
70
71 INPUT: 5 6 7 8
72 PRED: 8 9
73
74 Observe that:
75 1. Each token is predicted exactly once
76 2. For the last pair, we provide the full context, but only score the last two tokens
77
78 :param requests: list
79 A list of strings
80 string: str
81 String for which we are computing per-toke loglikelihood
82 :return: list
83 A list of pairs (logprob, isgreedy)
84 logprob: float
85 The log probability of `continuation`
86 isgreedy:
87 Whether `continuation` would be generated by greedy sampling from `context`
88 """
89 pass
90
91 # TODO: Add an optional max length
92 @abstractmethod

Callers 1

construct_requestsMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected