Skip to content

Commit

Permalink
fix(JAQPOT-407): remove extra config (#49)
Browse files Browse the repository at this point in the history
* fix(JAQPOT-407): remove extra config

* fix: remove dict access to featurizers and preprocessors

* chore: do not reformat openapi files
  • Loading branch information
alarv authored Nov 5, 2024
1 parent 5c92bfa commit b3dfb7b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[lint]
ignore = ["D100", "E722", "F401", "F403"]
exclude = ["src/api/openapi/**"]
[format]
exclude = ["src/api/openapi/**"]
2 changes: 1 addition & 1 deletion src/handlers/predict_pyg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def graph_post_handler(request: PredictionRequest) -> PredictionResponse:
feat_config = request.extra_config["torchConfig"]["featurizerConfig"]
feat_config = request.model.torch_config
featurizer = _load_featurizer(feat_config)
target_name = request.model.dependent_features[0].name
model_task = request.model.task
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/json_to_predreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def decode(request):
if feature.feature_type != "SMILES"
]
featurizers = []
if request.model.extra_config["featurizers"]:
for i in range(len(request.model.extra_config["featurizers"])):
featurizer_name = request.model.extra_config["featurizers"][i]["name"]
featurizer_config = request.model.extra_config["featurizers"][i]["config"]
if request.model.featurizers:
for featurizer in request.model.featurizers:
featurizer_name = featurizer.name
featurizer_config = featurizer.config
featurizer = recreate_featurizer(featurizer_name, featurizer_config)
featurizers.append(featurizer)
else:
Expand Down
19 changes: 7 additions & 12 deletions src/helpers/predict_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ def predict_onnx(model, preprocessor, dataset: JaqpotpyDataset, request):
}
onnx_prediction = model_session.run(None, input_feed)

if request.model.extra_config["preprocessors"]:
for i in reversed(range(len(request.model.extra_config["preprocessors"]))):
preprocessor_name = request.model.extra_config["preprocessors"][i]["name"]
preprocessor_config = request.model.extra_config["preprocessors"][i][
"config"
]
if request.model.preprocessors:
for preprocessor in reversed(request.model.preprocessors):
preprocessor_name = preprocessor.name
preprocessor_config = preprocessor.config
preprocessor_recreated = recreate_preprocessor(
preprocessor_name, preprocessor_config
)
Expand All @@ -144,13 +142,10 @@ def predict_onnx(model, preprocessor, dataset: JaqpotpyDataset, request):
for instance in onnx_prediction[1]:
rounded_instance = {k: round(v, 3) for k, v in instance.items()}
if (
request.model.extra_config["preprocessors"]
and request.model.extra_config["preprocessors"][0]["name"]
== "LabelEncoder"
request.model.preprocessors
and request.model.preprocessors[0].name == "LabelEncoder"
):
labels = request.model.extra_config["preprocessors"][0]["config"][
"classes_"
]
labels = request.model.preprocessors[0].config["classes_"]
rounded_instance = {labels[k]: v for k, v in rounded_instance.items()}

probs_list.append(rounded_instance)
Expand Down
6 changes: 3 additions & 3 deletions src/loggers/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import logging
from logging import Formatter
from logging import Formatter, RootLogger


class JsonFormatter(Formatter):
Expand All @@ -18,9 +18,9 @@ def format(self, record):
return json.dumps(json_record)


logger = logging.root
logger: RootLogger = logging.root
handler = logging.StreamHandler()
handler.setFormatter(JsonFormatter())
# handler.setFormatter(JsonFormatter())
logger.handlers = [handler]
logger.setLevel(logging.INFO)

Expand Down

0 comments on commit b3dfb7b

Please sign in to comment.