Service versioning and rollbacks

Titan Tutorial #6: Managing service versions for a price prediction model

Version Control Systems have a paramount importance in all types of software development, including of course the AI/ML models we work with in a daily basis. Version control applies to any kind of practice that tracks and provides control over changes to source code and, in the case of Data Science, also to datasets.

  • Provide effective means to effectively manage the versioning of the deployed services.

Creating a Neural Network model for Real Estate price prediction

Let’s illustrate this with a specific example. Imagine we are building a simple Neural Network to predict housing prices using this well-known dataset and the example shown in this great post by Joseph Lee Wei En.

  • Overall Quality (scale from 1 to 10)
  • Overall Condition (scale from 1 to 10)
  • Total Basement Area (in sq ft)
  • Number of Full Bathrooms
  • Number of Half Bathrooms
  • Number of Bedrooms above ground
  • Total Number of Rooms above ground
  • Number of Fireplaces
  • Garage Area (in sq ft)
  • Hidden Layer #1 (size=32)
model = Sequential([
Dense(32, activation='relu', input_shape=(10,)),
Dense(32, activation='relu'),
Dense(1, activation='sigmoid'),
])
model.compile(optimizer='sgd',
loss='binary_crossentropy',
metrics=['accuracy'])
hist = model.fit(X_train, Y_train,
batch_size=32, epochs=100,
validation_data=(X_val, Y_val))
# GET /loss 
print("Model Loss is {} ".format(model.evaluate(X_test, Y_test)[0]))
# GET /accuracy 
print("Model Accuracy is {} ".format(model.evaluate(X_test, Y_test)[1]))
# POST /prediction
body = json.loads(REQUEST)[‘body’]
input_params = json.loads(body)[‘data’]
input_array = np.array(input_params)
model.predict(input_array)
``yaml
titan: v1
service:
image: tensorflow
machine:
cpu: 2
memory: 2048MB
```
$ titan deploy
Model Accuracy is 0.8493150472640991Model Loss is 0.34327148111987876

“Improving” our model

Imagine now that we want to improve the performance of our Neural Network by adding additional layers and neurons:

model = Sequential([
Dense(1000, activation='relu', input_shape=(10,)),
Dense(1000, activation='relu'),
Dense(1000, activation='relu'),
Dense(1000, activation='relu'),
Dense(1, activation='sigmoid'),])
model.compile(optimizer='adam',loss='binary_crossentropy',
metrics=['accuracy'])
hist = model.fit(X_train, Y_train, batch_size=32, epochs=100,
Model Accuracy is 0.8995434045791626Model Loss is 0.25629456089511854
Overfitting going on here

Titan Rollbacks

Accidentally, in our attempt to improve the accuracy of our model, we have instead worsened its performance.

$ titan rollback
The subtle magic of a Rollback

Wrap-up

In this tutorial we have seen how Titan makes it really easy for Data Science Teams to manage their deployed services while keeping their usual code versioning tools. Moreover, we have also seen how to quickly rollback to previous versions in case something goes wrong in a deployed model using the rollback function of Titan.

Next Tutorial

If you are enjoying our tutorials, make sure to check our next post where we build and deploy a basic Sentiment Analysis model.

Foreword

Titan can help you to radically reduce and simplify the effort required to put AI/ML models into production, enabling Data Science teams to be agile, more productive and closer to the business impact of their developments.

Akoios: Frictionless solutions for modern data science.

Akoios