|
19 | 19 | logger = logging.getLogger(__name__) |
20 | 20 |
|
21 | 21 | FLAVOR_NAME = 'datamint' |
22 | | -PYTORCH_DATA_SUBPATH = "pytorch_data" |
23 | | - |
24 | | - |
25 | | -def _process_signature(signature: ModelSignature | None, |
26 | | - python_model: BaseDatamintModel) -> ModelSignature: |
27 | | - from mlflow.types import ParamSchema, ParamSpec |
28 | | - from mlflow.models.signature import _infer_signature_from_type_hints |
29 | | - |
30 | | - # Define inference parameters schema for BaseDatamintModel.predict() |
31 | | - # - mode (str): prediction mode to dispatch to (e.g. 'default', 'image', 'slice', etc.) |
32 | | - # - log_predictions (bool): whether to upload predictions as annotations to Datamint |
33 | | - # - model_name (str | None): name of the model used for tagging uploaded predictions |
34 | | - params_schema = ParamSchema([ |
35 | | - ParamSpec("mode", "string", "default"), |
36 | | - ParamSpec("log_predictions", "boolean", False), |
37 | | - ParamSpec("model_name", "string", None), |
38 | | - ]) |
39 | | - |
40 | | - if signature is None: |
41 | | - signature = _infer_signature_from_type_hints( |
42 | | - python_model=python_model, |
43 | | - context=None, |
44 | | - type_hints=python_model.predict_type_hints, |
45 | | - input_example=None, |
46 | | - ) |
47 | | - assert signature is not None |
48 | | - |
49 | | - # Merge existing params with our new params, ensuring no duplicates |
50 | | - existing_params: list[ParamSpec] = signature.params.params if signature.params else [] |
51 | | - existing_param_names = {param.name for param in existing_params} |
52 | | - new_params = [param for param in params_schema.params if param.name not in existing_param_names] |
53 | | - signature.params = ParamSchema(existing_params + new_params) |
54 | | - |
55 | | - return signature |
56 | 22 |
|
57 | 23 |
|
58 | | -def _process_input_example(input_example: ModelInputExample | None) -> tuple[ModelInputExample | None, dict[str, Any]]: |
| 24 | +def _process_input_example(input_example: ModelInputExample | None) -> tuple[ModelInputExample, dict[str, Any]]: |
59 | 25 | datamint_params = { |
60 | 26 | 'mode': 'default', |
61 | 27 | 'model_name': 'undefined_model_name', |
|
0 commit comments