mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Make logit bias work correctly(?) when prob is -inf
samplers'll do that to you though now i am curious: what kind of effect would running the bias before the samplers have? maybe a future option
This commit is contained in:
@@ -225,9 +225,6 @@ class HFTorchInferenceModel(HFInferenceModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
class KoboldLogitsWarperList(LogitsProcessorList):
|
class KoboldLogitsWarperList(LogitsProcessorList):
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __call__(
|
def __call__(
|
||||||
lw_self,
|
lw_self,
|
||||||
input_ids: torch.LongTensor,
|
input_ids: torch.LongTensor,
|
||||||
@@ -244,16 +241,10 @@ class HFTorchInferenceModel(HFInferenceModel):
|
|||||||
), f"Scores are None; processor '{processor}' is to blame"
|
), f"Scores are None; processor '{processor}' is to blame"
|
||||||
return scores
|
return scores
|
||||||
|
|
||||||
def new_get_logits_warper(
|
|
||||||
beams: int = 1,
|
|
||||||
) -> LogitsProcessorList:
|
|
||||||
return KoboldLogitsWarperList()
|
|
||||||
|
|
||||||
def new_sample(self, *args, **kwargs):
|
def new_sample(self, *args, **kwargs):
|
||||||
assert kwargs.pop("logits_warper", None) is not None
|
assert kwargs.pop("logits_warper", None) is not None
|
||||||
kwargs["logits_warper"] = new_get_logits_warper(
|
kwargs["logits_warper"] = KoboldLogitsWarperList()
|
||||||
beams=1,
|
|
||||||
)
|
|
||||||
if utils.koboldai_vars.newlinemode in ["s", "ns"]:
|
if utils.koboldai_vars.newlinemode in ["s", "ns"]:
|
||||||
kwargs["eos_token_id"] = -1
|
kwargs["eos_token_id"] = -1
|
||||||
kwargs.setdefault("pad_token_id", 2)
|
kwargs.setdefault("pad_token_id", 2)
|
||||||
|
@@ -267,6 +267,14 @@ class PhraseBiasLogitsProcessor:
|
|||||||
|
|
||||||
for batch in range(scores_shape[0]):
|
for batch in range(scores_shape[0]):
|
||||||
for token, bias in self._get_biased_tokens(input_ids[batch]).items():
|
for token, bias in self._get_biased_tokens(input_ids[batch]).items():
|
||||||
scores[batch][token] += bias
|
if bias > 0 and bool(scores[batch][token].isneginf()):
|
||||||
|
# Adding bias to -inf will do NOTHING!!! So just set it for
|
||||||
|
# now. There may be more mathishly correct way to do this
|
||||||
|
# but it'll work. Also, make sure the bias is actually
|
||||||
|
# positive. Don't give a -inf token more chance by setting
|
||||||
|
# it to -0.5!
|
||||||
|
scores[batch][token] = bias
|
||||||
|
else:
|
||||||
|
scores[batch][token] += bias
|
||||||
|
|
||||||
return scores
|
return scores
|
||||||
|
Reference in New Issue
Block a user