-
Notifications
You must be signed in to change notification settings - Fork 834
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
Cell execution telemetry #2610
Draft
yatarkan
wants to merge
10
commits into
openvinotoolkit:latest
Choose a base branch
from
yatarkan:yt/cell-execution-telemetry
base: latest
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Cell execution telemetry #2610
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05659da
Add telemetry initial description to readme
yatarkan 06c0572
Add collect telementry function to utils
yatarkan 934303c
Update readme with telemetry opt out details
yatarkan d2192a7
Add telemetry collection to 5 sample notebooks
yatarkan 65eea74
Switch to 1 for telemetry opt out, update readme
yatarkan 9aff298
Add explicit file names to collect telemetry function
yatarkan b0ab8b7
Unify telemetry snippets
yatarkan 38aa6e9
Add script for checking and adding telemetry snippet
yatarkan 13a0303
Enable checking telemetry snippet in ci
yatarkan d4399cf
Add telemetry snippet adding instructions
yatarkan 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import argparse | ||
from pathlib import Path | ||
import nbformat | ||
|
||
REPO_ROOT = Path(__file__).resolve().parents[1] | ||
|
||
|
||
def _get_telemetry_snippet(notebook_path: Path) -> str: | ||
if notebook_path.is_absolute(): | ||
notebook_path = notebook_path.relative_to(REPO_ROOT) | ||
return "".join( | ||
[ | ||
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n", | ||
"from notebook_utils import collect_telemetry\n", | ||
f'collect_telemetry("{notebook_path.name}")', | ||
] | ||
) | ||
|
||
|
||
def check_telemetry_snippet(notebook_path: Path) -> bool: | ||
if notebook_path.suffix != ".ipynb": | ||
print(f'Invalid file extension at path "{str(notebook_path)}". Only .ipynb files are supported.') | ||
return False | ||
telemetry_snippet = _get_telemetry_snippet(notebook_path) | ||
with open(notebook_path, "r") as notebook_file: | ||
nb_node: nbformat.NotebookNode = nbformat.read(notebook_file, as_version=4) | ||
for cell in nb_node["cells"]: | ||
if cell["cell_type"] != "code": | ||
continue | ||
cell_content: str = cell["source"] | ||
if telemetry_snippet in cell_content: | ||
return True | ||
return False | ||
|
||
|
||
def _add_telemetry_snippet(notebook_path: Path): | ||
if notebook_path.suffix != ".ipynb": | ||
raise Exception(f'Invalid file extension at path "{str(notebook_path)}". Only .ipynb files are supported.') | ||
with open(notebook_path, "r") as fr: | ||
nb_node: nbformat.NotebookNode = nbformat.read(fr, as_version=4) | ||
# Find cell with notebook_utils | ||
notebook_utils_url = "https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py" | ||
for i, cell in enumerate(nb_node["cells"]): | ||
if cell["cell_type"] != "code": | ||
continue | ||
cell_content: str = cell["source"] | ||
if notebook_utils_url in cell_content: | ||
nb_node["cells"][i]["source"] = cell_content + "\n\n" + _get_telemetry_snippet(notebook_path) | ||
break | ||
with open(notebook_path, "w") as fw: | ||
nbformat.write(nb_node, fw) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument( | ||
"-s", | ||
"--source", | ||
help="Specify the path to the notebook file, where telemetry snippet should be added", | ||
required=True, | ||
) | ||
|
||
args = parser.parse_args() | ||
file_path = Path(args.source) | ||
if not file_path.exists(): | ||
print(f'File does not exist at path "{file_path}"') | ||
exit(1) | ||
if not file_path.is_file(): | ||
print(f"Provided path is not a file") | ||
exit(1) | ||
_add_telemetry_snippet(file_path) |
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
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.
We can collect notebook directory assuming that each notebook downloads
notebook_utils.py
file to the same directory.