Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable Diffusion 1.4 #70

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Stable Diffusion 1.4 #70

wants to merge 15 commits into from

Conversation

bgoelTT
Copy link
Contributor

@bgoelTT bgoelTT commented Jan 20, 2025

This PR adds a flask server implementation of stable diffusion 1.4 and dockerizes it

It creates a new flask server that:

  • implements a warmup process whose completion gates the activation of the main inference and healthcheck endpoints
  • implements the main inference endpoint to submit prompts to be generated to the main backend thread
  • implements a healthcheck endpoint that will only return a 200 code once the server is warmed up and ready to generate images

@bgoelTT bgoelTT self-assigned this Jan 20, 2025
@bgoelTT bgoelTT requested review from tstescoTT and milank94 January 31, 2025 15:35
@tstescoTT
Copy link
Contributor

tstescoTT commented Jan 31, 2025

I'm going to ask you to rebase this to dev and PR to dev pending acceptance of new git flow proposed :)

@@ -0,0 +1,6 @@
TT_METAL_DOCKERFILE_VERSION=v0.53.0-rc34
TT_METAL_COMMIT_SHA_OR_TAG=4da4a5e79a13ece7ff5096c30cef79cb0c504f0e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reference to this commit in tt-metal anywhere? Curious how you selected this one.

Copy link
Contributor Author

@bgoelTT bgoelTT Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy+pasted this from the YOLOv4 server because that required a specific commit as the metal YOLOv4 improvements got reverted as couldn't pass CI.

Should I just use the latest release? That would be release v0.55.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use release v0.55.0 in 4582863

# SPDX-FileCopyrightText: © 2024 Tenstorrent AI ULC

from locust import HttpUser, task
from utils import sample_file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be get_sample_prompt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed locust tests in 016af35

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a locustfile needed for this demo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this isn't needed. The locust test here won't really measure performance, I want it to enqueue 5 prompts into the input queue and process them. I will add this to test_inference_api.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed locust tests in 016af35

app = Flask(__name__)

# var to indicate ready state
ready = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global variable ready : this flag is accessed and modified by multiple threads (warmup and request handlers). This may lead to race conditions. Consider using thread-safe mechanisms like threading.Lock or Event to manage state changes.

Copy link
Contributor Author

@bgoelTT bgoelTT Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforced mutual exclusion of ready flag in 835fc91 then fixed a bug in that implementeation in 63d973c


@app.route("/clean_up", methods=["POST"])
def clean_up():
with open(json_file_path, "r") as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated code blocks : the code repeatedly reads and writes json_file_path. This can be refactored into utility functions for cleaner logic:

def read_json_file(file_path):
    if not os.path.isfile(file_path):
        return {"prompts": []}
    with open(file_path, "r") as f:
        return json.load(f)

def write_json_file(file_path, data):
    with open(file_path, "w") as f:
        json.dump(data, f, indent=4)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored in a75d0e6

os.remove(
"models/demos/wormhole/stable_diffusion/demo/web_demo/input_prompts.json"
)
print("Deleted json")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use logging instead of print statements for better production diagnostics.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used logging instead of print in f5650c5

Copy link
Contributor

@milank94 milank94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback added.

For the license headers, the year should be set to 2025.

@bgoelTT bgoelTT requested a review from milank94 February 3, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants