Skip to content

Commit 6a84fe0

Browse files
rmitschRaphael Mitsch
andauthored
fix: Init engines lazily (#181)
* feat: HF classification uv script. * chore: Correct package name. * fix: Fix label normalization in classification HF dataset generation. * feat: Example uv script for zero-shot HF classification dataset creation and upload. * chore: Clean up. * fix: Fix classification dataset test. * chore: Rename OCR to Ingestion to better reflect task role. * chore: Migrate to sieves >= 0.15. * chore: Align with changes in v0.16.0. * fix: Make ingestion import conditional. * chore: Bump required sieves version. * fix: Use defensive approach to fetching objects from modules with optional support. * fix: Fix import. Remove HF jobs example. --------- Co-authored-by: Raphael Mitsch <raphael@climatiq.com>
1 parent cb1f94a commit 6a84fe0

17 files changed

Lines changed: 37 additions & 30 deletions

File tree

docs/guides/distillation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Here's how to distill a classification task using SetFit:
4040
import os
4141
import dspy
4242
from sieves.tasks import Classification
43-
from sieves.tasks.postprocessing.distillation.types import DistillationFramework
43+
from sieves.tasks.distillation.types import DistillationFramework
4444
from sieves import Pipeline, Doc
4545

4646
# 1. Run zero-shot classification task
@@ -219,7 +219,7 @@ output_path/
219219
Model2Vec is ideal for extremely fast inference with minimal resource usage:
220220

221221
```python
222-
from sieves.tasks.postprocessing.distillation.types import DistillationFramework
222+
from sieves.tasks.distillation.types import DistillationFramework
223223

224224
task.distill(
225225
base_model_id="minishlab/potion-base-8M",

sieves/engines/utils.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ def init_engine(
4141
"""
4242
model_type = type(model)
4343
module_engine_map = {
44-
dspy_: dspy_.DSPy,
45-
glix_: glix_.GliX,
46-
huggingface_: huggingface_.HuggingFace,
47-
langchain_: langchain_.LangChain,
48-
outlines_: outlines_.Outlines,
44+
dspy_: getattr(dspy_, "DSPy"),
45+
glix_: getattr(glix_, "GliX"),
46+
huggingface_: getattr(huggingface_, "HuggingFace"),
47+
langchain_: getattr(langchain_, "LangChain"),
48+
outlines_: getattr(outlines_, "Outlines"),
4949
}
5050

5151
for module, engine_type in module_engine_map.items():
52+
if engine_type is None:
53+
continue
54+
5255
try:
5356
module_model_types = module.Model.__args__
5457
except AttributeError:
@@ -64,6 +67,6 @@ def init_engine(
6467
return internal_engine
6568

6669
raise ValueError(
67-
f"Model type {model.__class__} is not supported. Please check the documentation and ensure you're "
68-
f"providing a supported model type."
70+
f"Model type {model.__class__} is not supported. Please check the documentation and ensure that (1) you're "
71+
f"providing a supported model type and that (2) the corresponding library is installed in your environment."
6972
)

sieves/tasks/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from sieves.tasks import predictive, preprocessing
44
from sieves.tasks.core import Task
5-
from sieves.tasks.postprocessing import DistillationFramework
5+
from sieves.tasks.distillation.types import DistillationFramework
66
from sieves.tasks.predictive import (
77
NER,
88
Classification,
File renamed without changes.

sieves/tasks/postprocessing/distillation/distillation_import.py renamed to sieves/tasks/distillation/distillation_import.py

File renamed without changes.

sieves/tasks/postprocessing/distillation/types.py renamed to sieves/tasks/distillation/types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
"""Distillation framework types."""
2+
13
from __future__ import annotations
24

35
import enum
46
from typing import Literal
57

68

79
class DistillationFramework(enum.Enum):
10+
"""Available distillation frameworks."""
11+
812
model2vec = "model2vec"
913
sentence_transformers = "sentence_transformers"
1014
setfit = "setfit"
1115

1216
@classmethod
1317
def all(cls) -> tuple[DistillationFramework, ...]:
14-
"""Returns all available engine types.
18+
"""Return all available engine types.
19+
1520
:return tuple[EngineType, ...]: All available engine types.
1621
"""
1722
return tuple(dist_type for dist_type in DistillationFramework)

sieves/tasks/postprocessing/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

sieves/tasks/predictive/classification/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from sieves.engines import EngineType, dspy_, glix_, huggingface_, langchain_, outlines_
1616
from sieves.engines.types import GenerationSettings
1717
from sieves.serialization import Config
18-
from sieves.tasks.postprocessing.distillation.distillation_import import model2vec, setfit
19-
from sieves.tasks.postprocessing.distillation.types import DistillationFramework
18+
from sieves.tasks.distillation.distillation_import import model2vec, setfit
19+
from sieves.tasks.distillation.types import DistillationFramework
2020
from sieves.tasks.predictive.bridges import GliXBridge
2121
from sieves.tasks.predictive.classification.bridges import (
2222
DSPyClassification,

sieves/tasks/predictive/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from sieves.serialization import Config
2525
from sieves.tasks import optimization
2626
from sieves.tasks.core import Task
27-
from sieves.tasks.postprocessing.distillation.types import DistillationFramework
27+
from sieves.tasks.distillation.types import DistillationFramework
2828
from sieves.tasks.predictive.bridges import TaskBridge, TaskPromptSignature, TaskResult
2929
from sieves.tasks.types import Model
3030

sieves/tasks/predictive/information_extraction/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from sieves.engines import EngineType, dspy_, glix_, langchain_, outlines_
1616
from sieves.engines.types import GenerationSettings
1717
from sieves.serialization import Config
18-
from sieves.tasks.postprocessing.distillation.types import DistillationFramework
18+
from sieves.tasks.distillation.types import DistillationFramework
1919
from sieves.tasks.predictive.core import FewshotExample as BaseFewshotExample
2020
from sieves.tasks.predictive.core import PredictiveTask
2121
from sieves.tasks.predictive.information_extraction.bridges import (

0 commit comments

Comments
 (0)