[Contribution suggestion] Allow explicitly passing in model_dir
Hi @1adrianb
Lovely package, first of all. I was testing it, and ran into (and have resolved in a fork) an issue with deploying to AWS Lambda:
- AWS Lambda only allows IO writes to the /tmp/ directory namespace
- The current package defaults to the
get_dirfrom torch.hub which is not within that namespace - Result: No models run on AWS Lambda from what I can deduce
Fix/enhancement (easy): Add model_dir: str = None to each of the __init__ for classes that use torch URL-loading functions. Downstream functions already support the explicit model_dir, but top-level class initialization e.g. in api.py module doesn't.
If you agree, I am happy to send you a PR on it:)
Best, Thoger.
Ok, I notice now that the same could probably also be achieved by globally calling torch.hub.set_dir or setting the TORCH_HOME environment variable.
Docs: https://pytorch.org/docs/stable/hub.html#torch.hub.get_dir
Personally not a big fan of using the global state but it should suffice for the use case 👍 Feel free to close this opened "Issue".