aws / aws/amazon-sagemaker-examples
Creating a smp.DistributedModel which uses 2 pre-trained tf.keras.Models in its call function.
- Dominant language
- Jupyter Notebook
- Stars
- 11k
- Forks
- 7k
- Avg merge
- 8h 29m
- Merged PRs (30d)
- 8
Description
Let's say we have 2 pre-trained tf.keras.Models which we first need to initialize and then load weights into. I want to create a third model that uses both of these models in its call function and I want to use model parallelism on this third model.
If we were to treat smp.DistributedModel like tf.keras.Model, the code would look something like this.
```
model_1 = create_build_and_load_weights_model_1()
model_2 = create_build_and_load_weights_model_2()
class smp_model(smp.DistributedModel):
def __init__(self, model_1, model_2):
# initialize Super
self.model_1 = model_1
self.model_2 = model_2
self.output_dense = tf.keras.layers.Dense(num_classes, activation = 'softmax')
def call(self, inputs):
x = self.model_1(inputs)
x = self.model_2(x)
outputs = self.output_dense(x)
return outputs
model_3 = smp_model(model_1, model_2)
# code to train the model_3
```
How can I implement this with smp.DistributedModel?
This example would be really helpful as it will cover way more use-cases where pre-trained models are fine-tuned.
Sagemaker_services used :- Sagemaker Model Parallel Library
Tensorflow version:- 2.X
Contributor guide
Assessment
This issue has not been assessed yet.