Skip to content

Commit 009e4df

Browse files
authored
Merge branch 'main' into fix/make-convert-token-to-string-pickleable
2 parents 3b3d926 + b55d314 commit 009e4df

File tree

5 files changed

+6
-15
lines changed

5 files changed

+6
-15
lines changed

docs/reference/generation/generation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Generation
44

55
# Generation
66

7-
Once an [Outlines model](../models) is constructed you can use `outlines.generate` to generate text. Standard LLM generation is possible via `outlines.generate.text`, along with a variety of structured generation methods described below. (For a detailed technical explanation of how structured generation works, you may review the [Structured Generation Explanation](./structured_generation_explanation.md) page)
7+
Once an [Outlines model](../models/models.md) is constructed you can use `outlines.generate` to generate text. Standard LLM generation is possible via `outlines.generate.text`, along with a variety of structured generation methods described below. (For a detailed technical explanation of how structured generation works, you may review the [Structured Generation Explanation](./structured_generation_explanation.md) page)
88

99
Before generating text, you must construct an `outlines.model`. Example:
1010

outlines/fsm/guide.py

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
)
1616

1717
from outlines import grammars
18-
from outlines.caching import cache
1918
from outlines.fsm.parsing import PartialLark, PartialParserState
2019

2120
if TYPE_CHECKING:
@@ -73,7 +72,6 @@ def copy(self):
7372
return self
7473

7574

76-
@cache()
7775
def cached_create_states_mapping(regex_string, tokenizer, *args, **kwargs):
7876
return uncached_create_states_mapping(regex_string, tokenizer, *args, **kwargs)
7977

tests/fsm/test_guide.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def convert_token_to_string(self, token):
5959
tokenizer = MockTokenizer()
6060
fsm = RegexGuide.from_regex(regex_str, tokenizer)
6161

62-
assert fsm.states_to_token_maps == {0: {1: 1}}
62+
assert fsm.states_to_token_maps.get_transitions() == {0: {1: 1}}
6363

6464
instruction = fsm.get_next_instruction(0)
6565
assert isinstance(instruction, Generate)
@@ -70,9 +70,6 @@ def convert_token_to_string(self, token):
7070

7171
assert fsm.is_final_state(0) is False
7272

73-
for state in fsm.final_states:
74-
assert fsm.is_final_state(state) is True
75-
7673

7774
def test_regex_multi_byte_llama_like():
7875
class MockTokenizer:
@@ -100,7 +97,7 @@ def convert_token_to_string(self, token):
10097
tokenizer = MockTokenizer()
10198
fsm = RegexGuide.from_regex(regex_str, tokenizer)
10299

103-
assert fsm.states_to_token_maps == {
100+
assert fsm.states_to_token_maps.get_transitions() == {
104101
0: {5: 1, 4: 2},
105102
1: {6: 3},
106103
3: {7: 4},
@@ -116,9 +113,6 @@ def convert_token_to_string(self, token):
116113

117114
assert fsm.is_final_state(0) is False
118115

119-
for state in fsm.final_states:
120-
assert fsm.is_final_state(state) is True
121-
122116

123117
def test_regex_multi_byte_gpt2_like():
124118
class MockTokenizer:
@@ -147,7 +141,7 @@ def convert_token_to_string(self, token):
147141
tokenizer = MockTokenizer()
148142
fsm = RegexGuide.from_regex(regex_str, tokenizer)
149143

150-
assert fsm.states_to_token_maps == {
144+
assert fsm.states_to_token_maps.get_transitions() == {
151145
0: {5: 1, 10: 2},
152146
1: {8: 5, 4: 3},
153147
2: {11: 3},
@@ -163,9 +157,6 @@ def convert_token_to_string(self, token):
163157

164158
assert fsm.is_final_state(0) is False
165159

166-
for state in fsm.final_states:
167-
assert fsm.is_final_state(state) is True
168-
169160

170161
def test_regex_final_state():
171162
"""Make sure that the FSM stays in the final state as we keep generating"""

tests/generate/test_integration_llamacpp.py

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def test_llama_cpp_pre_tokenizer_remains_broken():
274274
generate.choice(model, ["skirt", "dress", "pen", "jacket"])
275275

276276

277+
@pytest.mark.skip("Caching for guide was temporarily turned off")
277278
def test_RegexGuide_caching(model, temp_cache_dir):
278279
import llama_cpp
279280

tests/generate/test_integration_transformers.py

+1
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ def test_transformers_use_existing_model_and_tokenizer():
492492
assert isinstance(sequence, str)
493493

494494

495+
@pytest.mark.skip("Caching for guide was temporarily turned off")
495496
def test_RegexGuide_caching(temp_cache_dir):
496497
import outlines.caching
497498
from outlines.fsm.guide import cached_create_states_mapping

0 commit comments

Comments
 (0)