Registering model without weights with MLFLow - mlflow

I would like to be able to register untrained models with MLFLow to use as prototypes for instantiating models for training. I need this because we need to train thousands of models of the same type. Is this possible?

You could do it by logging the untrained model as an artifact.

Related

export an unfitted model to ONNX

I am building an API for training models, and figured I wanted to use ONNX to send the models back and forth.
I am testing with a sklearn XGboost model, and it seems that it is a requirement to fit the model before I can export it to onnx.
I want to define a custom or standard sklearn model, convert to onnx for transport, reopen and train, save in ONNX
Is this feasable at all?
My end goal is to have an API that can accept any sklearn, tensorflow or similar model in an untrained state and then train on the server.
Onnx is used to deliver model results, including pre and post-processing or other manipulations, "in production".
The assumption is the model is already trained and you only need to "predict" (or whatever similar action) on new data.
Sound like what you need is a Python (or other) code that will receive your API calls, translate them into the appropriate models, train the models, and then, if you want to be independent from an MLOps point of view, transform the result into Onnx.

How to create seperate mlflow custom models for training and prediction?

My requirement is to create separate Mlflow custom models for training and prediction.
I want to create training model and use those training model in prediction model
You can use mlflow.pyfunc to create a custom model.
You can find additional details of mlflow.pyfunc on this link.
This link will also help you get a overall view on models

Loading weights into a keras model from a .pb filed generated by tf.simple_save() in TensorFlow 1.15.2

I am struggling with restoring a keras model from a .pb file. I have seen a couple of posts explaining how to do inference using a model saved in .pb format, but what I need is to load the weights into a keras.Model class.
I have a function that returns an instance of the said original model, but untrained. I want to restore the weights of that model from the .pb file. My goal is to then truncate the model and use the truncated model for other purposes.
So far the furthest I've gotten is using the tf.saved_model.load(session, ['serving'], export_dir) function to get a tensorflow.core.protobuf.meta_graph_pb2.MetaGraphDef object. From here I can access the graph_def attribute, and from there the nodes.
How can I go from that to getting the weights and then loading those into the instance of the untrained keras Model?
Maybe if that's not doable there is a way to "truncate" the graph_def somehow and then make inference using that?

Make sure BERT model does not load pretrained weights?

I want to make sure my BertModel does not loads pre-trained weights. I am using auto class (hugging face) which loads model automatically.
My question is how do I load bert model without pretrained weights?
Use AutoConfig instead of AutoModel:
from transformers import AutoConfig
config = AutoConfig.from_pretrained('bert-base-uncased')
model = AutoModel.from_config(config)
this should set up the model without loading the weights.
Documentation here and here
You can re-initialize of a PreTrainedModel class with init_weights method (Huggingface Documentation), if the model is already loaded with pre-trained weights.
Maybe you can just load the model with pretrained weights, iterate over model parameters and set the model parameters randomly with whatever initialization technique you prefer.

Keras: better way to implement layer-wise training model?

I'm currently learning implementing layer-wise training model with Keras. My solution is complicated and time-costing, could someone give me some suggestions to do it in a easy way? Also could someone explain the topology of Keras especially the relations among nodes.outbound_layer, nodes.inbound_layer and how did they associated with tensors: input_tensors and output_tensors? From the topology source codes on github, I'm quite confused about:
input_tensors[i] == inbound_layers[i].inbound_nodes[node_indices[i]].output_tensors[tensor_indices[i]]
Why the inbound_nodes contain output_tensors, I'm not clear about the relations among them....If I wanna remove layers in certain positions of the API model, what should I firstly remove? Also, when adding layers to some certain places, what shall I do first?
Here is my solution to a layerwise training model. I can do it on Sequential model and now trying to implement in on the API model:
To do it, I'm simply add a new layer after finish previous training and re-compile (model.compile()) and re-fit (model.fit()).
Since Keras model requires output layer, I would always add an output layer. As a result, each time when I wanna add a new layer, I have to remove the output layer then add it back. This can be done using model.pop(), in this case model has to be a keras.Sequential() model.
The Sequential() model supports many useful functions including model.add(layer). But for customised model using model API: model=Model(input=...., output=....), those pop() or add() functions are not supported and implement them takes some time and maybe not convenient.

Resources