-
Notifications
You must be signed in to change notification settings - Fork 273
enable profiling for video-comprehension sample #1958
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
Closed
alexey-belyakov
wants to merge
2
commits into
huggingface:main
from
alexey-belyakov:profile_options_for_video_comprehension_example
Closed
Changes from all commits
Commits
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 hidden or 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,21 @@ | ||
| from argparse import ArgumentParser | ||
|
|
||
|
|
||
| def add_profiling_args(parser: ArgumentParser) -> None: | ||
| parser.add_argument( | ||
| "--profiling_warmup_steps", | ||
| default=0, | ||
| type=int, | ||
| help="Number of steps to ignore for profiling.", | ||
| ) | ||
| parser.add_argument( | ||
| "--profiling_steps", | ||
| default=0, | ||
| type=int, | ||
| help="Number of steps to capture for profiling.", | ||
| ) | ||
| parser.add_argument( | ||
| "--profiling_record_shapes", | ||
| action="store_true", | ||
| help="Record shapes when enabling profiling.", | ||
| ) |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| import json | ||
| import logging | ||
| import os | ||
| import sys | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
|
|
@@ -32,6 +33,12 @@ | |
| ) | ||
|
|
||
|
|
||
| project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")) | ||
| if project_root not in sys.path: | ||
| sys.path.insert(0, project_root) | ||
|
Comment on lines
+36
to
+38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
| from examples.common_parser import add_profiling_args # noqa: E402 | ||
|
|
||
|
|
||
| logging.basicConfig( | ||
| format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", | ||
| datefmt="%m/%d/%Y %H:%M:%S", | ||
|
|
@@ -118,6 +125,7 @@ def main(): | |
| help="Whether to enable Habana Flash Attention in recompute mode on first token generation. This gives an opportunity of splitting graph internally which helps reduce memory consumption.", | ||
| ) | ||
|
|
||
| add_profiling_args(parser) | ||
| args = parser.parse_args() | ||
|
|
||
| os.environ.setdefault("EXPERIMENTAL_WEIGHT_SHARING", "FALSE") | ||
|
|
@@ -186,6 +194,9 @@ def main(): | |
| ) | ||
| torch.hpu.synchronize() | ||
|
|
||
| from optimum.habana.utils import HabanaProfile | ||
|
|
||
| HabanaProfile.enable() | ||
| start = time.perf_counter() | ||
| for i in range(args.n_iterations): | ||
| generate_ids = model.generate( | ||
|
|
@@ -196,12 +207,16 @@ def main(): | |
| ignore_eos=args.ignore_eos, | ||
| use_flash_attention=args.use_flash_attention, | ||
| flash_attention_recompute=args.flash_attention_recompute, | ||
| profiling_steps=args.profiling_steps, | ||
| profiling_warmup_steps=args.profiling_warmup_steps, | ||
| profiling_record_shapes=args.profiling_record_shapes, | ||
| ) | ||
| generate_texts = processor.batch_decode( | ||
| generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False | ||
| ) | ||
| end = time.perf_counter() | ||
| duration = end - start | ||
| HabanaProfile.disable() | ||
|
|
||
| # Let's calculate the number of generated tokens | ||
| n_input_tokens = inputs["input_ids"].shape[1] | ||
|
|
||
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.
Why do we need these lines?
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.
to import this:
from examples.common_parser import add_profiling_argsI do believe it's good approach to use the
examplesfolder for shared code among examplesalternatively:
PYTHONPATH, but this would cause changes to all tests and instructions for running these scripts.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.
@regisss can you check my comment please
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.
@alexey-belyakov, I would suggest to wait for #1931 to be merged as there is some rebase of profiling code.
Besides that, probably another solution in case you do not want to rewrite code multiple times is to create a file like examples_utils.py, or the like, under optimum/habana which is already in the path. To avoid the solution you provided which is not very clear.
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.
Honestly I'm also fine in not creating a new file for the three profiling args that are repeating : ) But I can understand the pain
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.
optimum/habana does not contain code related to examples.
examplesfolder is the most obvious folder for files related to examples.It is always possible to rename the file after adding more logic to it.
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.
I think that solution is okay. Can you still check if it still holds after #1931 as suggested by @12010486 please?