Skip to content

Commit

Permalink
big reshuffle but this should work
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKaum committed Aug 16, 2024
1 parent 3ef4d40 commit 01c305b
Show file tree
Hide file tree
Showing 34 changed files with 244 additions and 302 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ docs/build
.venv
benchmarks/results
**/target/
**/dist/
17 changes: 8 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion benchmarks/bench_numba_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import interegular
import numba

from outlines_core.fsm import regex

from .common import setup_tokenizer
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from transformers import AutoTokenizer

from outlines_core.fsm.guide import RegexGuide
from outlines_core.models.transformers import TransformerTokenizer
from transformers import AutoTokenizer


def setup_tokenizer():
Expand Down
72 changes: 0 additions & 72 deletions bindings/python/.gitignore

This file was deleted.

18 changes: 11 additions & 7 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[package]
name = "outlines-core-python"
name = "python-bindings"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "outlines_core"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.22.0"
outlines-core = { path = "../../outlines-core" }
# outlines-core = { path = "../../outlines-core" }

[profile.release-lto]
inherits = "release"
lto = true

[lib]
name = "_lib"
crate-type = ["cdylib"]
path = "rust/lib.rs"
6 changes: 6 additions & 0 deletions bindings/python/Manifest.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
graft python
graft rust
graft tests
include Cargo.toml
global-exclude */__pycache__/*
global-exclude *.pyc
133 changes: 126 additions & 7 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,134 @@
[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2", "setuptools-rust"]
build-backend = "setuptools.build_meta"

[project]
name = "outlines_core"
authors= [{name = "Outlines Developers"}]
description = "Structured Text Generation in Rust"
requires-python = ">=3.8"
license = {text = "Apache-2.0"}
keywords=[
"machine learning",
"deep learning",
"language models",
"structured generation",
]
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
dependencies = [
"interegular",
"numpy<2.0.0",
"cloudpickle",
"diskcache",
"pydantic>=2.0",
"numba",
"referencing",
"jsonschema",
"tqdm",
"datasets",
"typing_extensions",
]
dynamic = ["version"]
[tool.maturin]
features = ["pyo3/extension-module"]

[project.optional-dependencies]
test = [
"pre-commit",
"pytest",
"pytest-benchmark",
"pytest-cov",
"pytest-mock",
"coverage[toml]>=5.1",
"diff-cover",
"accelerate",
"beartype<0.16.0",
"huggingface_hub",
"torch",
"transformers",
"pillow",
]

[project.urls]
homepage = "https://github.com/outlines-dev/outlines-core"
documentation = "https://outlines-dev.github.io/outlines-core/"
repository = "https://github.com/outlines-dev/outlines-core/"

[project.readme]
file="README.md"
content-type = "text/markdown"

[tool.setuptools]
packages = ["outlines_core"]
package-dir = {"" = "src"}

[tool.setuptools.package-data]
"outlines" = ["py.typed"]

[tool.setuptools_scm]
write_to = "src/outlines_core/_version.py"

[tool.pytest.ini_options]
testpaths = ["tests"]
filterwarnings = [
"error",
"ignore::numba.core.errors.NumbaPendingDeprecationWarning",
"ignore::pydantic.warnings.PydanticDeprecatedSince20",
"ignore::FutureWarning:transformers.*",
"ignore::FutureWarning:huggingface_hub.*",
"ignore::UserWarning",
"ignore::DeprecationWarning:pyairports.*",
]

[tool.mypy]
exclude=["examples"]
enable_incomplete_feature = ["Unpack"]

[[tool.mypy.overrides]]
module = [
"jsonschema.*",
"numpy.*",
"cloudpickle.*",
"diskcache.*",
"pydantic.*",
"pytest",
"referencing.*",
"torch.*",
"transformers.*",
"huggingface_hub",
"interegular.*",
"datasets.*",
"numba.*",
]
ignore_missing_imports = true

[tool.coverage.run]
omit = [
"src/outlines_core/_version.py",
"tests/*",
]
branch = true

[tool.coverage.report]
omit = [
"tests/*",
]
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
"\\.\\.\\.",
]
show_missing = true

[tool.diff_cover]
compare_branch = "origin/main"
diff_range_notation = ".."

[[tool.setuptools-rust.ext-modules]]
target = "outlines_core._lib" # The last part of the name (e.g. "_lib") has to match lib.name in Cargo.toml, but you can add a prefix to nest it inside of a Python package.
71 changes: 71 additions & 0 deletions bindings/python/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// use std::collections::{BTreeMap, BTreeSet};

// use ::outlines_core as core_lib;
// use pyo3::types::{PyAnyMethods, PyDict, PyModule, PyModuleMethods, PySet};
use pyo3::{pyfunction, pymodule, wrap_pyfunction, Bound, PyResult};


#[pymodule]
mod _lib {
use pyo3::prelude::*;

/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}
}

// #[pymodule]
// fn outlines_core(m: &Bound<'_, PyModule>) -> PyResult<()> {
// m.add_function(wrap_pyfunction!(add, m)?)?;
// Ok(())
// }

// #[pyfunction]
// Create an FSM index end-to-end.
//
// Args:
// fsm_transitions (Dict[Tuple[int, int], int]): FSM transitions mapping.
// alphabet_symbol_mapping (Dict[str, int]): Alphabet symbol mapping.
// alphabet_anything_value (int): Value representing 'anything' in the alphabet.
// fsm_initial (int): Initial state of the FSM.
// fsm_finals (Set[int]): Set of final states in the FSM.
// vocabulary (Dict[str, List[int]]): Vocabulary mapping.
//
// Returns:
// Dict[int, Set[Tuple[int, int]]]: The created FSM index.
//
// Raises:
// ValueError: If the input types are incorrect or conversion fails.
// fn create_fsm_index_end_to_end(
// fsm_transitions: Bound<PyDict>,
// alphabet_symbol_mapping: Bound<PyDict>,
// alphabet_anything_value: i32,
// fsm_initial: i32,
// fsm_finals: Bound<PySet>,
// vocabulary: Bound<PyDict>,
// ) -> PyResult<BTreeMap<i32, BTreeSet<(i32, i32)>>> {
// let fsm_transitions_map = fsm_transitions.extract::<BTreeMap<(i32, i32), i32>>()?;
// let alphabet_symbol_mapping_map = alphabet_symbol_mapping.extract::<BTreeMap<char, i32>>()?;
// let fsm_finals_set = fsm_finals.extract::<BTreeSet<i32>>()?;
// let vocabulary_map = vocabulary.extract::<BTreeMap<String, Vec<i32>>>()?;

// let res = core_lib::create_fsm_index_end_to_end_rust(
// &fsm_transitions_map,
// &alphabet_symbol_mapping_map,
// alphabet_anything_value,
// fsm_initial,
// &fsm_finals_set,
// &vocabulary_map,
// );

// Ok(res)
// }

// Outlines is a Generative Model Programming Framework.
// #[pymodule]
// fn outlines_core(m: &Bound<'_, PyModule>) -> PyResult<()> {
// m.add_function(wrap_pyfunction!(create_fsm_index_end_to_end, m)?)?;
// Ok(())
// }
3 changes: 3 additions & 0 deletions setup.cfg → bindings/python/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ per-file-ignores =
**/__init__.py:F401,F403
exclude =
normalai/_version.py

[bdist_wheel]
py_limited_api=cp38
Loading

0 comments on commit 01c305b

Please sign in to comment.