Skip to content

Commit

Permalink
Move index to fsm
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Dec 1, 2023
1 parent a774693 commit b57e149
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
set_seed,
)

from outlines.index.parsing import PartialLark, PartialPythonIndenter
from outlines.fsm.parsing import PartialLark, PartialPythonIndenter

revision = None
checkpoint = "Salesforce/codegen-350M-mono"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion outlines/index/index.py → outlines/fsm/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import interegular

from outlines.index.fsm import create_fsm_index_tokenizer, make_deterministic_fsm
from outlines.fsm.regex import create_fsm_index_tokenizer, make_deterministic_fsm

if TYPE_CHECKING:
from outlines.models.tokenizer import Tokenizer
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion outlines/index/parsing.py → outlines/fsm/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from lark.parsers.lalr_interactive_parser import InteractiveParser
from lark.parsers.lalr_parser import LALR_Parser, ParseConf, ParserState, _Parser

from outlines.index.fsm import (
from outlines.fsm.regex import (
fsm_union,
get_sub_fsms_from_seq,
make_deterministic_fsm,
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 3 additions & 6 deletions outlines/generate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

from pydantic import BaseModel

from outlines.fsm.fsm import RegexFSM, StopAtTokenFSM
from outlines.fsm.json_schema import build_regex_from_object, get_schema_from_signature
from outlines.fsm.types import python_types_to_regex
from outlines.generate.generator import SequenceGenerator
from outlines.generate.samplers import Sampler, multinomial
from outlines.index.index import RegexFSM, StopAtTokenFSM
from outlines.index.json_schema import (
build_regex_from_object,
get_schema_from_signature,
)
from outlines.index.types import python_types_to_regex


def text(model, max_tokens: Optional[int] = None, *, sampler: Sampler = multinomial):
Expand Down
4 changes: 2 additions & 2 deletions outlines/generate/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import torch

from outlines.index.index import FSMState
from outlines.fsm.fsm import FSMState

if TYPE_CHECKING:
from outlines.fsm.fsm import FSM
from outlines.generate.samplers import Sampler
from outlines.index.index import FSM


@dataclasses.dataclass(frozen=True)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/index/test_index.py → tests/fsm/test_fsm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from outlines.index.index import RegexFSM, StopAtTokenFSM
from outlines.fsm.fsm import RegexFSM, StopAtTokenFSM


def test_stop_at_token():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from pydantic import BaseModel, constr

from outlines.index.json_schema import (
from outlines.fsm.json_schema import (
BOOLEAN,
INTEGER,
NULL,
Expand Down
8 changes: 4 additions & 4 deletions tests/index/test_parsing.py → tests/fsm/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from lark.indenter import DedentError
from lark.lexer import UnexpectedCharacters, UnexpectedToken

from outlines.index.parsing import PartialLark, PartialPythonIndenter
from outlines.fsm.parsing import PartialLark, PartialPythonIndenter


def test_partial_parsing():
lp = PartialLark.open_from_package(
"tests",
"partial_python.lark",
["index"],
["fsm"],
parser="lalr",
postlex=PartialPythonIndenter(),
start="file_input",
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_partial_parsing():
lp = PartialLark.open_from_package(
"tests",
"partial_python.lark",
["index"],
["fsm"],
parser="lalr",
postlex=PartialPythonIndenter(),
start="file_input",
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_sequential_parse_example():
lp = PartialLark.open_from_package(
"tests",
"partial_python.lark",
["index"],
["fsm"],
parser="lalr",
postlex=PartialPythonIndenter(),
start="file_input",
Expand Down
2 changes: 1 addition & 1 deletion tests/index/test_fsm.py → tests/fsm/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numba
import pytest

from outlines.index.fsm import (
from outlines.fsm.regex import (
_walk_fsm,
create_fsm_index,
create_fsm_index_end_to_end,
Expand Down
2 changes: 1 addition & 1 deletion tests/index/test_types.py → tests/fsm/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from outlines.index.types import (
from outlines.fsm.types import (
BOOLEAN,
DATE,
DATETIME,
Expand Down
2 changes: 1 addition & 1 deletion tests/generate/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import torch

from outlines.fsm.fsm import FSMState
from outlines.generate.generator import (
SequenceGenerator,
bias_logits,
Expand All @@ -15,7 +16,6 @@
token_generator,
update_token_ids,
)
from outlines.index.index import FSMState


def test_sequence_generator_class():
Expand Down
2 changes: 1 addition & 1 deletion tests/generate/test_integration_transfomers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import outlines.generate as generate
import outlines.models as models
from outlines.index.fsm import reduced_vocabulary
from outlines.fsm.regex import reduced_vocabulary
from outlines.models.transformers import TransformerTokenizer


Expand Down

0 comments on commit b57e149

Please sign in to comment.