Skip to content

Commit

Permalink
Add model warm up for debug (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Oct 28, 2024
1 parent 99dc37f commit 226f4b2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
model_predict = loaded_model.signatures["serving_default"]


def warm_up_model():
"""Sends a dummy request to the model to 'warm it up'."""
dummy_query = "SELECT * FROM users WHERE id = 1"
query_seq = TOKENIZER.texts_to_sequences([dummy_query])
query_vec = pad_sequences(query_seq, maxlen=MAX_LEN)
input_tensor = tf.convert_to_tensor(query_vec, dtype=tf.float32)
_ = model_predict(input_tensor) # Make a dummy prediction to initialize the model
print("Model warmed up and ready to serve requests.")


@app.route("/predict", methods=["POST"])
def predict():
if not request.json or "query" not in request.json:
Expand Down Expand Up @@ -54,4 +64,5 @@ def predict():


if __name__ == "__main__":
warm_up_model()
app.run(host="0.0.0.0", port=8000, debug=True)

0 comments on commit 226f4b2

Please sign in to comment.