Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TQDM to track index compilation progress #915

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ repos:
- id: mypy
args: [--allow-redefinition]
exclude: ^examples/
additional_dependencies: [types-tqdm]
13 changes: 12 additions & 1 deletion outlines/fsm/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
anything_else,
)
from numba.typed.typedobjectutils import _nonoptional
from tqdm import tqdm

if TYPE_CHECKING:
from outlines.models.tokenizer import Tokenizer
Expand Down Expand Up @@ -692,6 +693,12 @@ def create_fsm_index_end_to_end(
seen: Set[int] = set()
next_states = {fsm_info.initial}

pbar = tqdm(
total=len(set(fsm_info.transitions.values()))
+ 1, # all transitions plus initial
desc="Compiling FSM index for all state transitions",
)

while next_states:
start_state = next_states.pop()

Expand All @@ -713,7 +720,11 @@ def create_fsm_index_end_to_end(
if end_state not in seen:
next_states.add(end_state)

seen.add(start_state)
if start_state not in seen:
pbar.update(1)
seen.add(start_state)

pbar.close()

return states_to_token_subsets

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [
"referencing",
"jsonschema",
"requests",
"tqdm"
]
dynamic = ["version"]

Expand Down
Loading