-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve outlines.processors, add integration tests to test_generate.py
- Loading branch information
Showing
7 changed files
with
316 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import mlx.core as mx | ||
import numpy as np | ||
import torch | ||
|
||
from outlines.processors import OutlinesLogitsProcessor | ||
|
||
|
||
class HalvingLogitsProcessor(OutlinesLogitsProcessor): | ||
"""Simply halve the passed logits""" | ||
|
||
def process_logits(input_ids, logits): | ||
return logits / 2 | ||
|
||
|
||
# logits: (4, 30,000 ) dtype=float | ||
# input_ids shape: (4, 2048) dtype=int | ||
logit_processor_inputs = { | ||
"torch": { | ||
"logits": torch.rand((4, 30000), dtype=torch.float), | ||
"input_ids": torch.randint(low=0, high=30000, size=(4, 2048), dtype=torch.int), | ||
}, | ||
"numpy": { | ||
"logits": np.random.rand(4, 30000).astype(np.float32), | ||
"input_ids": np.random.randint(low=0, high=30000, size=(4, 2048)), | ||
}, | ||
"mlx": { | ||
"logits": mx.random.uniform( | ||
low=-1e9, high=1e9, shape=(4, 30000), dtype=mx.float32 | ||
), | ||
"input_ids": mx.random.randint( | ||
low=0, high=30000, shape=(4, 2048), dtype=mx.int32 | ||
), | ||
}, | ||
} | ||
|
||
|
||
class LogitsProcessorBenchmark: | ||
params = logit_processor_inputs.keys() | ||
|
||
def setup(self, array_library): | ||
self.logits_processor = HalvingLogitsProcessor() | ||
lp_inputs = self.inputs[array_library] | ||
self.logits = lp_inputs["logits"] | ||
self.input_ids = lp_inputs["input_ids"] | ||
|
||
def time_logits_processor(self, array_library): | ||
self.logits_processor(self.logits, self.input_ids) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from .structured import ( | ||
BaseLogitsProcessor, | ||
CFGLogitsProcessor, | ||
FSMLogitsProcessor, | ||
JSONLogitsProcessor, | ||
OutlinesLogitsProcessor, | ||
RegexLogitsProcessor, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.