Skip to content

Commit 4eaa0db

Browse files
authored
Cell execution telemetry (#2610)
Ticket: CVS-149317 CVS-160620
1 parent 397e235 commit 4eaa0db

File tree

181 files changed

+1299
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+1299
-179
lines changed

.ci/check_notebooks.py

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from patch_notebooks import DEVICE_WIDGET, DEVICE_WIDGET_NEW
55
from install_instructions import check_install_instructions
66
from scarf_pixel import check_scarf_tag
7+
from telemetry_snippet import check_telemetry_snippet
78
from pathlib import Path
89

910
NOTEBOOKS_ROOT = Path(__file__).resolve().parents[1]
@@ -34,6 +35,7 @@ def main():
3435
no_tocs = []
3536
no_device = []
3637
no_scarf_tag = []
38+
no_telemetry_snippet = []
3739
no_install_instructions = []
3840

3941
def complain(message):
@@ -73,6 +75,9 @@ def complain(message):
7375
if not check_scarf_tag(nb_path):
7476
no_scarf_tag.append(str(nb_path.relative_to(NOTEBOOKS_ROOT)))
7577
complain(f"FAILED: {nb_path.relative_to(NOTEBOOKS_ROOT)}: Scarf Pixel tag is not found")
78+
if not check_telemetry_snippet(nb_path):
79+
no_telemetry_snippet.append(str(nb_path.relative_to(NOTEBOOKS_ROOT)))
80+
complain(f"FAILED: {nb_path.relative_to(NOTEBOOKS_ROOT)}: telemetry snippet is not found")
7681
if not check_install_instructions(nb_path):
7782
no_install_instructions.append(str(nb_path.relative_to(NOTEBOOKS_ROOT)))
7883
complain(f"FAILED: {nb_path.relative_to(NOTEBOOKS_ROOT)}: Install Instructions section is not found")
@@ -94,6 +99,11 @@ def complain(message):
9499
print("\n".join(no_scarf_tag))
95100
print("\nYou can generate Scarf Pixel tag with the following command:\n python .ci/scarf_pixel.py -s <PATH>")
96101
print("==================================")
102+
if no_telemetry_snippet:
103+
print("NO TELEMETRY SNIPPET:")
104+
print("\n".join(no_telemetry_snippet))
105+
print("\nYou can generate telemetry snippet with the following command:\n python .ci/telemetry_snippet.py -s <PATH>")
106+
print("==================================")
97107
if no_install_instructions:
98108
print("NO INSTALL INSTRUCTIONS SECTION:")
99109
print("\n".join(no_install_instructions))

.ci/spellcheck/.pyspelling.wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ PixelShuffleUpsampleNetwork
687687
pixelwise
688688
Pixtral
689689
pixtral
690+
PII
690691
PIL
691692
PNDM
692693
png

.ci/telemetry_snippet.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import argparse
2+
from pathlib import Path
3+
import nbformat
4+
5+
REPO_ROOT = Path(__file__).resolve().parents[1]
6+
7+
8+
def _get_telemetry_snippet(notebook_path: Path) -> str:
9+
if notebook_path.is_absolute():
10+
notebook_path = notebook_path.relative_to(REPO_ROOT)
11+
return "".join(
12+
[
13+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
14+
"from notebook_utils import collect_telemetry\n\n",
15+
f'collect_telemetry("{notebook_path.name}")',
16+
]
17+
)
18+
19+
20+
def check_telemetry_snippet(notebook_path: Path) -> bool:
21+
if notebook_path.suffix != ".ipynb":
22+
print(f'Invalid file extension at path "{str(notebook_path)}". Only .ipynb files are supported.')
23+
return False
24+
telemetry_snippet = _get_telemetry_snippet(notebook_path)
25+
with open(notebook_path, "r") as notebook_file:
26+
nb_node: nbformat.NotebookNode = nbformat.read(notebook_file, as_version=4)
27+
for cell in nb_node["cells"]:
28+
if cell["cell_type"] != "code":
29+
continue
30+
cell_content: str = cell["source"]
31+
if telemetry_snippet in cell_content:
32+
return True
33+
return False
34+
35+
36+
def _add_telemetry_snippet(notebook_path: Path):
37+
if notebook_path.suffix != ".ipynb":
38+
raise Exception(f'Invalid file extension at path "{str(notebook_path)}". Only .ipynb files are supported.')
39+
with open(notebook_path, "r") as fr:
40+
nb_node: nbformat.NotebookNode = nbformat.read(fr, as_version=4)
41+
# Find cell with notebook_utils
42+
notebook_utils_url = "https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py"
43+
for i, cell in enumerate(nb_node["cells"]):
44+
if cell["cell_type"] != "code":
45+
continue
46+
cell_content: str = cell["source"]
47+
if notebook_utils_url in cell_content:
48+
nb_node["cells"][i]["source"] = cell_content + "\n\n" + _get_telemetry_snippet(notebook_path)
49+
break
50+
with open(notebook_path, "w") as fw:
51+
nbformat.write(nb_node, fw)
52+
53+
54+
if __name__ == "__main__":
55+
parser = argparse.ArgumentParser()
56+
57+
parser.add_argument(
58+
"-s",
59+
"--source",
60+
help="Specify the path to the notebook file, where telemetry snippet should be added",
61+
required=True,
62+
)
63+
64+
args = parser.parse_args()
65+
file_path = Path(args.source)
66+
if not file_path.exists():
67+
print(f'File does not exist at path "{file_path}"')
68+
exit(1)
69+
if not file_path.is_file():
70+
print(f"Provided path is not a file")
71+
exit(1)
72+
_add_telemetry_snippet(file_path)

CONTRIBUTING.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ To do this, there are a few requirements that all notebooks need to pass.
132132
5. Add **Table of content** to top of the Notebook, it helps to get quick fist understanding of content and ease of navigation in the dev environment. There is no need to think about it during development, it can be built or updated after changes with `.ci\table_of_content.py`. Just run the script with the parameter `-s/--source`, specifying a Notebook or a folder with several notebooks as value, the changes will be applied to all of them.
133133
6. Add **Installation Instructions** section to the top of the notebook (after "Table of content") and to the corresponding `README.md` file in the notebook directory. See existing notebooks for the reference.
134134
7. Add Scarf Pixel tag for analytics to the notebook (at the end of the first cell) and to the corresponding `README.md` file (to the end of the file). Add relative path to the notebook or `README.md` file as `path` URL query parameter. Example: `<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=<RELATIVE_FILE_PATH>" />`. You can use the following command to generate the tag and add it to the file: `python .ci/scarf_pixel.py -s <PATH>`.
135-
8. In case if notebook has specific requirements on python version or OS, it should be noted on top of notebook (before any code blocks) using
135+
8. Add telemetry snippet to the notebook file (e.g. to the cell with fetching notebook_utils file) for tracking notebook execution. Add notebook file name as a parameter to `collect_telemetry()` function. You can use the following command to generate the snippet and add it to the notebook file: `python .ci/telemetry_snippet.py -s <PATH>`. Snippet example:
136+
```python
137+
# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry
138+
from notebook_utils import collect_telemetry
139+
collect_telemetry("<NOTEBOOK_NAME>.ipynb")
140+
```
141+
1. In case if notebook has specific requirements on python version or OS, it should be noted on top of notebook (before any code blocks) using
136142
following colored block:
137143
```
138144
<div class="alert alert-block alert-danger"> <b>Important note:</b> This notebook requires python >= 3.9. Please make sure that your environment fulfill to this requirement before running it </div>

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ List of all notebooks is available in [index file](./notebooks/README.md).
2828
- [To Launch all Notebooks](#to-launch-all-notebooks)
2929
- [🧹 Cleaning Up](#-cleaning-up)
3030
- [⚠️ Troubleshooting](#️-troubleshooting)
31+
- [📊 Telemetry](#-telemetry)
3132
- [📚 Additional Resources](#-additional-resources)
3233
- [🧑‍💻 Contributors](#-contributors)
3334
- [❓ FAQ](#-faq)
@@ -171,6 +172,30 @@ or create an [issue](https://github.com/openvinotoolkit/openvino_notebooks/issue
171172
- If OpenVINO is installed globally, do not run installation commands in a terminal where `setupvars.bat` or `setupvars.sh` are sourced.
172173
- For Windows installation, it is recommended to use _Command Prompt (`cmd.exe`)_, not _PowerShell_.
173174

175+
[![-----------------------------------------------------](https://user-images.githubusercontent.com/10940214/155750931-fc094349-b6ec-4e1f-9f9a-113e67941119.jpg)]()
176+
<div id='-telemetry'></div>
177+
178+
## 📊 Telemetry
179+
180+
When you execute a notebook cell that contains `collect_telemetry()` function, telemetry data is collected to help us improve your experience.
181+
This data only indicates that the cell was executed and does **not** include any personally identifiable information (PII).
182+
183+
By default, anonymous telemetry data is collected, limited solely to the execution of the notebook.
184+
This telemetry does **not** extend to any Intel software, hardware, websites, or products.
185+
186+
If you prefer to disable telemetry, you can do so at any time by commenting out the specific line responsible for data collection in the notebook:
187+
```python
188+
# collect_telemetry(...)
189+
```
190+
Also you can disable telemetry collection by setting `SCARF_NO_ANALYTICS` or `DO_NOT_TRACK` environment variable to `1`:
191+
```bash
192+
export SCARF_NO_ANALYTICS=1
193+
# or
194+
export DO_NOT_TRACK=1
195+
```
196+
197+
Scarf is used for telemetry purposes. Refer to [Scarf documentation](https://docs.scarf.sh/) to understand how the data is collected and processed.
198+
174199
[![-----------------------------------------------------](https://user-images.githubusercontent.com/10940214/155750931-fc094349-b6ec-4e1f-9f9a-113e67941119.jpg)]()
175200
<div id='-additional-resource'></div>
176201

notebooks/3D-pose-estimation-webcam/3D-pose-estimation.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@
135135
" f.write(r.text)\n",
136136
"\n",
137137
"import notebook_utils as utils\n",
138-
"import engine3js as engine"
138+
"import engine3js as engine\n",
139+
"\n",
140+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
141+
"from notebook_utils import collect_telemetry\n",
142+
"\n",
143+
"collect_telemetry(\"3D-pose-estimation.ipynb\")"
139144
]
140145
},
141146
{

notebooks/3D-segmentation-point-clouds/3D-segmentation-point-clouds.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@
7373
" )\n",
7474
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
7575
"\n",
76-
"from notebook_utils import download_file, device_widget"
76+
"from notebook_utils import download_file, device_widget\n",
77+
"\n",
78+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
79+
"from notebook_utils import collect_telemetry\n",
80+
"\n",
81+
"collect_telemetry(\"3D-segmentation-point-clouds.ipynb\")"
7782
]
7883
},
7984
{

notebooks/action-recognition-webcam/action-recognition-webcam.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@
106106
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
107107
" )\n",
108108
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
109-
"import notebook_utils as utils"
109+
"import notebook_utils as utils\n",
110+
"\n",
111+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
112+
"from notebook_utils import collect_telemetry\n",
113+
"\n",
114+
"collect_telemetry(\"action-recognition-webcam.ipynb\")"
110115
]
111116
},
112117
{

notebooks/animate-anyone/animate-anyone.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@
9292
"\n",
9393
"clone_repo(\"https://github.com/itrushkin/Moore-AnimateAnyone.git\")\n",
9494
"\n",
95-
"%load_ext skip_kernel_extension"
95+
"%load_ext skip_kernel_extension\n",
96+
"\n",
97+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
98+
"from notebook_utils import collect_telemetry\n",
99+
"\n",
100+
"collect_telemetry(\"animate-anyone.ipynb\")"
96101
]
97102
},
98103
{

notebooks/async-api/async-api.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@
8282
" )\n",
8383
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
8484
"\n",
85-
"import notebook_utils as utils"
85+
"import notebook_utils as utils\n",
86+
"\n",
87+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
88+
"from notebook_utils import collect_telemetry\n",
89+
"\n",
90+
"collect_telemetry(\"async-api.ipynb\")"
8691
]
8792
},
8893
{

notebooks/auto-device/auto-device.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,12 @@
311311
" r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\")\n",
312312
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
313313
"\n",
314-
"from notebook_utils import download_file"
314+
"from notebook_utils import download_file\n",
315+
"\n",
316+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
317+
"from notebook_utils import collect_telemetry\n",
318+
"\n",
319+
"collect_telemetry(\"auto-device.ipynb\")"
315320
]
316321
},
317322
{

notebooks/bark-text-to-audio/bark-text-to-audio.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@
8989
" r = requests.get(\n",
9090
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
9191
" )\n",
92-
" open(\"notebook_utils.py\", \"w\").write(r.text)"
92+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
93+
"\n",
94+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
95+
"from notebook_utils import collect_telemetry\n",
96+
"\n",
97+
"collect_telemetry(\"bark-text-to-audio.ipynb\")"
9398
]
9499
},
95100
{

notebooks/big-transfer-quantization/tensorflow-bit-image-classification-nncf-quantization.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@
9292
" r = requests.get(\n",
9393
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
9494
" )\n",
95-
" open(\"notebook_utils.py\", \"w\").write(r.text)"
95+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
96+
"\n",
97+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
98+
"from notebook_utils import collect_telemetry\n",
99+
"\n",
100+
"collect_telemetry(\"tensorflow-bit-image-classification-nncf-quantization.ipynb\")"
96101
]
97102
},
98103
{

notebooks/blip-visual-language-processing/blip-visual-language-processing.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@
219219
"end = time.perf_counter() - start\n",
220220
"\n",
221221
"# postprocess result\n",
222-
"answer = processor.decode(out[0], skip_special_tokens=True)"
222+
"answer = processor.decode(out[0], skip_special_tokens=True)\n",
223+
"\n",
224+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
225+
"from notebook_utils import collect_telemetry\n",
226+
"\n",
227+
"collect_telemetry(\"blip-visual-language-processing.ipynb\")"
223228
]
224229
},
225230
{

notebooks/catvton/catvton.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@
9191
" r = requests.get(\n",
9292
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py\",\n",
9393
" )\n",
94-
" open(\"cmd_helper.py\", \"w\").write(r.text)"
94+
" open(\"cmd_helper.py\", \"w\").write(r.text)\n",
95+
"\n",
96+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
97+
"from notebook_utils import collect_telemetry\n",
98+
"\n",
99+
"collect_telemetry(\"catvton.ipynb\")"
95100
]
96101
},
97102
{

notebooks/clip-language-saliency-map/clip-language-saliency-map.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@
118118
" r = requests.get(\n",
119119
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
120120
" )\n",
121-
" open(\"notebook_utils.py\", \"w\").write(r.text)"
121+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
122+
"\n",
123+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
124+
"from notebook_utils import collect_telemetry\n",
125+
"\n",
126+
"collect_telemetry(\"clip-language-saliency-map.ipynb\")"
122127
]
123128
},
124129
{

notebooks/clip-zero-shot-image-classification/clip-zero-shot-classification.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@
9797
" r = requests.get(\n",
9898
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
9999
" )\n",
100-
" open(\"notebook_utils.py\", \"w\").write(r.text)"
100+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
101+
"\n",
102+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
103+
"from notebook_utils import collect_telemetry\n",
104+
"\n",
105+
"collect_telemetry(\"clip-zero-shot-classification.ipynb\")"
101106
]
102107
},
103108
{

notebooks/controlnet-stable-diffusion/controlnet-stable-diffusion.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@
149149
" \"https://download.pytorch.org/whl/cpu\",\n",
150150
")\n",
151151
"pip_install(\"--no-deps\", \"controlnet-aux>=0.0.6\")\n",
152-
"pip_install(\"openvino>=2023.1.0\")"
152+
"pip_install(\"openvino>=2023.1.0\")\n",
153+
"\n",
154+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
155+
"from notebook_utils import collect_telemetry\n",
156+
"\n",
157+
"collect_telemetry(\"controlnet-stable-diffusion.ipynb\")"
153158
]
154159
},
155160
{

notebooks/convert-to-openvino/convert-to-openvino.ipynb

+21
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@
5151
"\"openvino>=2024.4.0\" \"requests\" \"tqdm\" \"transformers>=4.31\" \"onnx!=1.16.2\" \"torch>=2.1\" \"torchvision\" \"tf_keras\""
5252
]
5353
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": null,
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"import requests\n",
61+
"from pathlib import Path\n",
62+
"\n",
63+
"if not Path(\"notebook_utils.py\").exists():\n",
64+
" r = requests.get(\n",
65+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
66+
" )\n",
67+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
68+
"\n",
69+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
70+
"from notebook_utils import collect_telemetry\n",
71+
"\n",
72+
"collect_telemetry(\"convert-to-openvino.ipynb\")"
73+
]
74+
},
5475
{
5576
"attachments": {},
5677
"cell_type": "markdown",

notebooks/ct-segmentation-quantize/ct-segmentation-quantize-nncf.ipynb

+6-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@
150150
"\n",
151151
"if not Path(\"./async_pipeline.py\").exists():\n",
152152
" download_file(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/ct-segmentation-quantize/async_pipeline.py\")\n",
153-
"from async_pipeline import show_live_inference"
153+
"from async_pipeline import show_live_inference\n",
154+
"\n",
155+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
156+
"from notebook_utils import collect_telemetry\n",
157+
"\n",
158+
"collect_telemetry(\"ct-segmentation-quantize-nncf.ipynb\")"
154159
]
155160
},
156161
{

0 commit comments

Comments
 (0)