Don’t hide the complex functionality behind too generic functions.

def load_model(filename: str):
model = create_complex_model()
return model

def create_complex_model():
base = create_base_model()
return complex_model



However, what if you need to replace the base model with something else but still compatible with the head model? It is not so easy to do with this setting. Because both parts of the model are saved in the same file and restored simultaneously. (Example: image or text models with pre-trained backbones).

A better option would be to expose internal functions and classes. It would require more efforts from a caller to re-construct the process but will make it more flexible.

base = create_base_model()