Skip to content
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
2 changes: 2 additions & 0 deletions src/huggingface_inference_toolkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def check_and_register_custom_pipeline_from_directory(model_dir):
logger.info(f"Found custom pipeline at {custom_module}")
spec = importlib.util.spec_from_file_location(HF_MODULE_NAME, custom_module)
if spec:
# add the whole directory to path for submodlues
sys.path.insert(0, model_dir)
# import custom handler
pipeline = importlib.util.module_from_spec(spec)
sys.modules[HF_MODULE_NAME] = pipeline
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/custom_handler/custom_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_method(input):
"""reverse string"""
return input[::-1]
4 changes: 3 additions & 1 deletion tests/resources/custom_handler/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from custom_utils import test_method
class PreTrainedPipeline:
def __init__(self, path):
self.path = path

def __call__(self, data):
return data
res = test_method(data)
return res
2 changes: 1 addition & 1 deletion tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_local_custom_pipeline():
pipeline = check_and_register_custom_pipeline_from_directory(model_dir)
payload = "test"
assert pipeline.path == model_dir
assert pipeline(payload) == payload
assert pipeline(payload) == payload[::-1]


def test_remote_custom_pipeline():
Expand Down