Skip to content

Commit ffab2ac

Browse files
lapp0rlouf
authored andcommittedMay 23, 2024
Use TQDM to track index compilation progress
1 parent 6f655ca commit ffab2ac

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
 

‎.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ repos:
3030
- id: mypy
3131
args: [--allow-redefinition]
3232
exclude: ^examples/
33+
additional_dependencies: [types-tqdm]

‎outlines/fsm/regex.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
anything_else,
2727
)
2828
from numba.typed.typedobjectutils import _nonoptional
29+
from tqdm import tqdm
2930

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

696+
pbar = tqdm(
697+
total=len(set(fsm_info.transitions.values()))
698+
+ 1, # all transitions plus initial
699+
desc="Compiling FSM index for all state transitions",
700+
)
701+
695702
while next_states:
696703
start_state = next_states.pop()
697704

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

716-
seen.add(start_state)
723+
if start_state not in seen:
724+
pbar.update(1)
725+
seen.add(start_state)
726+
727+
pbar.close()
717728

718729
return states_to_token_subsets
719730

‎pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies = [
3535
"referencing",
3636
"jsonschema",
3737
"requests",
38+
"tqdm"
3839
]
3940
dynamic = ["version"]
4041

0 commit comments

Comments
 (0)
Please sign in to comment.