Search code examples
razure-machine-learning-service

Operationalize custom R model in Azure ML without loading it on every call of web service


I am trying to serve an R model as a web service in Azure ML.

The model is trained locally and uses Xgboost and other packages. I have had issues submitting it directly from AzureML package due to size exceeding 130 MB. The workaround was to upload all the packages and the model as zip to Azure and source it from there.

The current issue is that the model is loaded from a zip file by Azure ML EVERY time the service is called making the response time very slow (4.5 seconds). How do I restructure the code so that the model is loaded only once from the file. Thank you for your help.

Here is how it looks in AzureML enter image description here And here is what is inside Execute R script enter image description here


Solution

  • Here is a clever trick for running initialization steps only the first time and not on every subsequent call.

    My understanding is that you would wrap the first 3 statements (that is through line 11) of your script in the following if statement:

    if (!is.element("my_env", search()))
    

    The if statement would also contain the initialization of the my_env variable as shown in the example used in that blog:

    R optimization example