ArneBinder / pytorch-ie-hydra-template-1

PyTorch-IE Hydra Template
8 stars 1 forks source link

Replace sys args with values from files #122

Closed ArneBinder closed 1 year ago

ArneBinder commented 1 year ago

This PR implements replace_sys_args_with_values_from_files() and calls it at the beginning of each hydra based main entry scripts. This allows to replace command line arguments with the content of json files. The functionality is triggered by either using LOAD_ARG: or LOAD_MULTI_ARG:. In the latter case, the value is expected to be a list that will get unwrapped ([1,2,3] becomes 1,2,3) to be compatible with hydra --multirun functionality. This is primarily developed to ease multirun experiments (train -> predict -> evaluate).

Example call:

# This will set the value for `+dataset.data_files.test` to the content of the respective json at the nested key `serializer` / `path`.
python src/evaluate_documents.py \
metric.layer=entities \
dataset.document_type=src.document.types.TextDocumentWithLabeledEntitiesAndRelations \
+dataset.data_files.test=LOAD_MULTI_ARG:logs/prediction/multiruns/default/2023-08-21_16-14-22/job_return_value.json:serializer/path \
--multirun