-
Notifications
You must be signed in to change notification settings - Fork 31
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
(shortfin-sd) Adds tooling for performance measurement. #380
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
23dc337
Add basic perf measurements
eagarvey-amd ac001a9
Improvements to logging/metrics reporting
eagarvey-amd 8a3476b
Remove extra newline
eagarvey-amd fdb50d1
Rename utils -> metrics
eagarvey-amd d8ff71a
fixup indents in prints
eagarvey-amd d32ceb6
Merge branch 'main' into sdxl-perf
monorimet e49ee52
Update decorator implementation.
eagarvey-amd 4aab75a
Merge branch 'main' into sdxl-perf
monorimet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import logging | ||
import time | ||
import asyncio | ||
from typing import Callable, Any | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
# measurement helper | ||
def measure(fn): | ||
|
||
""" | ||
Decorator log test start and end time of a function | ||
:param fn: Function to decorate | ||
:return: Decorated function | ||
Example: | ||
>>> @timed | ||
>>> def test_fn(): | ||
>>> time.sleep(1) | ||
>>> test_fn() | ||
""" | ||
|
||
def wrapped_fn(*args: Any, **kwargs: Any) -> Any: | ||
start = time.time() | ||
ret = fn(*args, **kwargs) | ||
duration_str = get_duration_str(start) | ||
logger.info(f"Completed {fn.__qualname__} in {duration_str}") | ||
return ret | ||
|
||
async def wrapped_fn_async(*args: Any, **kwargs: Any) -> Any: | ||
start = time.time() | ||
ret = await fn(*args, **kwargs) | ||
duration_str = get_duration_str(start) | ||
logger.info(f"Completed {fn.__qualname__} in {duration_str}") | ||
if fn.__qualname__ == "ClientGenerateBatchProcess.run": | ||
sps_str = get_samples_per_second(start, *args) | ||
logger.info(f"SAMPLES PER SECOND = {sps_str}") | ||
return ret | ||
|
||
if asyncio.iscoroutinefunction(fn): | ||
return wrapped_fn_async | ||
else: | ||
return wrapped_fn | ||
|
||
|
||
def get_samples_per_second(start, *args: Any) -> str: | ||
duration = time.time() - start | ||
bs = args[0].gen_req.num_output_images | ||
sps = str(float(bs) / duration) | ||
return sps | ||
|
||
|
||
def get_duration_str(start: float) -> str: | ||
"""Get human readable duration string from start time""" | ||
duration = time.time() - start | ||
duration_str = f"{round(duration * 1e3)}ms" | ||
return duration_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's going on with this? Seems like you should just have a kwarg on the decorator to tell it what to do. There's a standard (but tricky) idiom for that using functools.partial...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointer -- I didn't end up using partial here but adapted to take a few kwargs. There's still some yuck there where we ping attributes of the decorated method's class to figure out batch size, but still more flexible than before. I may revisit later.