Skip to content

Commit

Permalink
run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKaum committed Aug 22, 2024
1 parent 4a3bb7e commit 29eeb3e
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 40 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/python_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [main]
push:
branches: [main]

permissions:
contents: read

Expand All @@ -19,7 +19,7 @@ jobs:
with:
python-version: "3.10"
- uses: pre-commit/[email protected]

tests:
name: Run the tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -58,47 +58,47 @@ jobs:
defaults:
run:
working-directory: bindings/python

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
with:
cache: pip
python-version: "3.11"

- name: Set up environment
run: |
pip install --upgrade "coverage[toml]>=5.1" diff-cover
- uses: actions/download-artifact@v3
with:
name: coverage-data

- name: Fetch master for coverage diff
run: |
git fetch --no-tags --prune origin main
- name: Combine coverage & fail if it's <100%.
run: |
# Combine coverage files (not needed now, but maybe later)
# python -m coverage combine
# Produce an html report with absolute coverage information
cd bindgins/python && python -m coverage html --skip-covered --skip-empty
# Report relative coverage and write to the workflow's summary
cd bindings/python && python -m coverage xml
diff-cover coverage.xml --markdown-report=coverage.md --fail-under=100 || (cat coverage.md >> $GITHUB_STEP_SUMMARY && exit 1)
- name: Upload HTML report if check failed.
uses: actions/upload-artifact@v3
with:
name: html-report
path: htmlcov
if: ${{ failure() }}
if: ${{ failure() }}

linux:
runs-on: ${{ matrix.platform.runner }}
Expand Down Expand Up @@ -320,4 +320,4 @@ jobs:
# PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
# with:
# command: upload
# args: --non-interactive --skip-existing wheels-*/*
# args: --non-interactive --skip-existing wheels-*/*
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"bindings/python",
]

resolver = "2"
resolver = "2"
2 changes: 1 addition & 1 deletion bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.22.0"
outlines-core = { path = "../../outlines-core" }
outlines-core = { path = "../../outlines-core" }
4 changes: 2 additions & 2 deletions bindings/python/outlines_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Outlines is a Generative Model Programming Framework."""
import outlines_core.models
from _outlines_core_rs import __version__
from _outlines_core_rs import __version__

__all__ = ["models", "__version__"]
__all__ = ["models", "__version__"]
2 changes: 1 addition & 1 deletion bindings/python/outlines_core/fsm/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def allowed_token_ids(self, state: FSMState) -> Optional[Iterable[int]]:
return next_instruction.tokens

def next_state(self, state: FSMState, token_id: int) -> FSMState:
return FSMState(self.get_next_state(state, token_id))
return FSMState(self.get_next_state(state, token_id))
2 changes: 1 addition & 1 deletion bindings/python/outlines_core/fsm/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,4 @@ def is_final_state(self, state: int) -> bool:
return state in self.final_states

def copy(self):
return self
return self
2 changes: 1 addition & 1 deletion bindings/python/outlines_core/fsm/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,4 @@ def get_schema_from_signature(fn: Callable) -> str:
)
model = create_model(fn_name, **arguments)

return model.model_json_schema()
return model.model_json_schema()
18 changes: 9 additions & 9 deletions bindings/python/outlines_core/fsm/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
cast,
)

from interegular.fsm import (
FSM,
Alphabet,
State,
TransitionKey,
_AnythingElseCls,
anything_else,
)
from _outlines_core_rs import ( # noqa: F401
FSMInfo,
_walk_fsm,
Expand All @@ -30,6 +22,14 @@
get_vocabulary_transition_keys,
state_scan_tokens,
)
from interegular.fsm import (
FSM,
Alphabet,
State,
TransitionKey,
_AnythingElseCls,
anything_else,
)

if TYPE_CHECKING:
from outlines_core.models.tokenizer import Tokenizer
Expand Down Expand Up @@ -479,4 +479,4 @@ def create_fsm_index_tokenizer(
if subset is not None:
subset[tokenizer.eos_token_id] = state

return states_to_token_subsets, empty_token_ids
return states_to_token_subsets, empty_token_ids
2 changes: 1 addition & 1 deletion bindings/python/outlines_core/fsm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ def datetime_format_fn(sequence: str) -> datetime.datetime:
else:
raise NotImplementedError(
f"The Python type {python_type} is not supported. Please open an issue."
)
)
2 changes: 1 addition & 1 deletion bindings/python/outlines_core/integrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def convert_token_to_string(token: Union[str, bytes]) -> str:

tokenizer.convert_token_to_string = convert_token_to_string

return tokenizer
return tokenizer
2 changes: 1 addition & 1 deletion bindings/python/outlines_core/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

from .transformers import Transformers, TransformerTokenizer, mamba, transformers

LogitsGenerator = Union[Transformers]
LogitsGenerator = Union[Transformers]
2 changes: 1 addition & 1 deletion bindings/python/outlines_core/models/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def convert_token_to_string(self, token: str) -> str:
represented by the special characted `Ġ`. This prevents matching a raw
token that includes `Ġ` with a string.
"""
...
...
2 changes: 1 addition & 1 deletion bindings/python/outlines_core/models/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,4 @@ def mamba(
model_kwargs=model_kwargs,
tokenizer_kwargs=tokenizer_kwargs,
model_class=MambaForCausalLM,
)
)
9 changes: 6 additions & 3 deletions bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

use ::outlines_core as core_lib;
use pyo3::{pyclass, pyfunction, pymethods, pymodule, types::{PyAnyMethods, PyDict, PyModule, PyModuleMethods}, wrap_pyfunction, Bound, PyResult, Python};
use pyo3::{
pyclass, pyfunction, pymethods, pymodule,
types::{PyAnyMethods, PyDict, PyModule, PyModuleMethods},
wrap_pyfunction, Bound, PyResult, Python,
};
use std::collections::{HashMap, HashSet};

#[pymodule]
Expand Down Expand Up @@ -131,7 +134,7 @@ pub fn create_fsm_index_end_to_end<'py>(
&vocabulary_transition_keys,
start_state,
);

for (token_id, end_state) in token_ids_end_states {
if let Ok(existing_dict) = states_to_token_subsets.get_item(start_state) {
existing_dict.set_item(token_id, end_state).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/tests/fsm/test_fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ def convert_token_to_string(self, token):
assert fsm.is_final_state(state)

state = fsm.next_state(state=5, token_id=103)
assert fsm.is_final_state(state)
assert fsm.is_final_state(state)
2 changes: 1 addition & 1 deletion bindings/python/tests/fsm/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,4 @@ def test_reduced_vocabulary_with_rare_tokens(rare_token):
tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2")
tokenizer = adapt_tokenizer(tokenizer=tokenizer)
tokenizer.vocabulary[rare_token] = max(tokenizer.vocabulary.values()) + 1
reduced_vocabulary(tokenizer)
reduced_vocabulary(tokenizer)
2 changes: 1 addition & 1 deletion outlines-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod regex;
pub mod regex;

0 comments on commit 29eeb3e

Please sign in to comment.