-
Notifications
You must be signed in to change notification settings - Fork 871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use model archiver utility for complex projects? #566
Comments
@sagjounkani: You could create a zip file of the dependency python files in the required folder hierarchy and supply this zip file using the You can refer to the waveglow text-to-speech-synthesizer example |
Yep, I encountered this problem as well. Even though the files specified by |
@harshbafna Thank you for the resolution, I was able to deploy the model. I found it easier to append the path for dependencies in my custom handler file compared to the process followed in the waveglow text-to-speech-synthesizer example. Not sure of a standard way to approach this. Agree with @misrasaurabh1 that if somehow the directory structure is preserved within the --extra-files it will make things easier. |
@sagjounkani: Your solution may work when TorchServe is deployed on your localhost, however, it will fail in case you need to register the model on a remote host where the extra files will not be available on the server's file system. There are multiple ways you can add you dependency python files in the model-archive :
We will take this up as a part of #561 . Also, if you think the above-provided options are too complicated please feel free to raise a feature request. |
While I think this is certainly an area where torchserve should support a simpler approach, let me share my work around with you. The implementation here just recursively copies any sub directories (of the included directories) over. You can actually trick this into doing what you want by creating a temporary directory into which you symlink the directories you originally wanted to include. TEMP_DIR=$(mktemp -d)
ln -s "$(pwd)/dir_a" $TEMP_DIR
ln -s "$(pwd)/dir_b" $TEMP_DIR
# call torch-model-archiver with `--extra-files $TEMP_DIR` here
rm -rf $TEMP_DIR The resulting archive will include the top level directories named |
How does it work exactly with the egg file / wheel file? You still need to sys.path.append("egg_file_location") right? And you can only get the location from the context model_dir + the name you gave it, correct? My use case is as follows. Let's assume I implement my own basehandler in the shared module.
Is that correct? |
@mhashas :
The model's temporary directory, where the model archive (.mar) is extracted, is already added in the In your case, you can add the zip file in your model archive using You can refer to the waveglow text-to-speech-synthesizer example
|
@harshbafna I think in the end @hatzel's response is the easiest one to implement and does solve my problem. |
@mhashas Other way can be to package the wheel file and a custom requirements.txt file in your model archive. TorchServe will automatically install the package. |
I am trying to serve the model from the NCRFpp project using torchserve. The files that are required by my custom handler.py file are in multiple folders and have import statements which refer to this folder hierarchy. The model archiver zips all these files and extracts into a temporary folder at the same level without this folder hierarchy, leading to runtime errors because the import statements fail. How do I ensure that the import statements work, with same folder hierarchy as used during development, while using torchserve?
The text was updated successfully, but these errors were encountered: