Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Export model as SavedModel #9

#1

There are other discussions about exporting the model to be used outside of ludwig, however are there any plans to allow exporting the model to a SavedModel? I tried digging around and reached a wall.
The use cases for this is that Google Cloud Platform's CloudML lets you easily deploy tensorflow models exported as SavedModel which means folks don't have to worry about hosting the model.
I would like to know if there's plan for this, if not it would be great if you can give me a pointer on how to achieve this
Thanks so much for the awesome work on Ludwig!

  • replies 7
  • views 7.4K
  • likes 0

Hi Jad, thank you for asking about this. I'm not familiar with that interface to be honest, i have to do some digging myself to figura out what one should do in order to make make it work.
My concern by the way is always the same: preprocessing and postprocessing. Even if you load the model on CloudML, if you don't preprocess and postprocess data in the same way you are going to be able to use it.
Anyway, I certainly need to dig deeper into this before being able to give a definitive answer.
if you are interested about this topic and want to help me figure it out, I believe you should look at ```
ludwig/models/model.py in particular the load and save function to see how I'm doing it at the moment, so that's a starting point I can give you for sure.
Let me add that it would be amaxing to have a solution that really achieves something like I just have to provide a file/zip/directory to service and it just deploys it without additional effort, I'm just not sure what's the easier way to get there.

Thanks Piero, I'm glad to hear that this is issue is indeed interesting.

Here's how I got started: I changed the tf.train.Saver() into a self.saver = tf.saved_model.Builder("saved_model").
(The path needs fixing for later on but that's just for a demo now).
However the saved_model works differently than the saver. It expects inputs/outputs which I'm not sure where to get them from. Here's an example of how saved_model is used: https://stackoverflow.com/a/44329200/1599122 . Do you have any idea where I can get those required data for the saved_model builder? As I already got the saved_model to work but the folder was empty because I wasn't giving it the proper data. Thanks!

I understand the concern regarding the preprocessing/postprocessing, but I guess it would be manageable when you're only training for 5-6 classes (text classification).

If we get the saved_model to work, then theoretically you just need to deploy it to Google's CloudML and start predicting using their REST API. I'd be happy to help with this as much as possible (I have the time for it) but do note that I'm a JavaScript developer so I'm so much slower in Python (& I don't really have experience in tensorflow & ML) 😅

Reading the example, this part:

inp = g.get_tensor_by_name("real_A_and_B_images:0")
out = g.get_tensor_by_name("generator/Tanh:0")

sigs[signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY] = \
    tf.saved_model.signature_def_utils.predict_signature_def(
        {"in": inp}, {"out": out})

Suggests that models need to have one input and one output. Ludwig models can have multiple inputs and multiple outputs, so unless there's a way to support that with tf.saved_model.Builder, in general it would not be possible to save Ludwig models with this approach, as they make too restrictive simplifying assumptions on the I/O of the model.

#5
#6

Got it, will take a closer look then.
Anyway, the preprocessing and postprocessing are still issues, you would still have to perform them with Ludwig or to reimplement them, so I'm not 100% sure it would be a viable easy solution anyway.

#7

Thanks Piero! Just to make sure, does that mean for a simple classification of:
text | class
some text | class_a
another text | class_b

For this kind of example, we'd have to replace class_a with 0 and class_a with 1? or does it mean we'd have to "pre-process" the text as well?
Thanks!

#8

The JSON file contains all the mappings (both classes and text) that are needed ;)