Unverified Commit 611ed639 authored by J-shang's avatar J-shang Committed by GitHub
Browse files

[Doc] clean useless files (#4707)

parent 5a7c6eca
......@@ -7,7 +7,6 @@ Tutorials
:maxdepth: 2
:hidden:
tutorials/nni_experiment
tutorials/hello_nas
tutorials/nasbench_as_dataset
tutorials/pruning_quick_start_mnist
......@@ -17,13 +16,6 @@ Tutorials
.. ----------------------
.. cardlinkitem::
:header: Start and Manage a New Experiment
:description: Familiarize yourself with Pythonic API to manage a hyper-parameter tuning experiment
:link: tutorials/nni_experiment.html
:image: ../img/thumbnails/overview-31.png
:tags: Experiment/HPO
.. cardlinkitem::
:header: HPO Quickstart with PyTorch
:description: Use HPO to tune a PyTorch FashionMNIST model
......
......@@ -30,27 +30,6 @@ Tutorials
/tutorials/pruning_speedup
.. raw:: html
<div class="sphx-glr-thumbcontainer" tooltip="Start and Manage a New Experiment">
.. only:: html
.. figure:: /tutorials/images/thumb/sphx_glr_nni_experiment_thumb.png
:alt: Start and Manage a New Experiment
:ref:`sphx_glr_tutorials_nni_experiment.py`
.. raw:: html
</div>
.. toctree::
:hidden:
/tutorials/nni_experiment
.. raw:: html
<div class="sphx-glr-thumbcontainer" tooltip="Quantization reduces model size and speeds up inference time by reducing the number of bits req...">
......
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Start and Manage a New Experiment\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configure Search Space\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"search_space = {\n \"C\": {\"_type\": \"quniform\", \"_value\": [0.1, 1, 0.1]},\n \"kernel\": {\"_type\": \"choice\", \"_value\": [\"linear\", \"rbf\", \"poly\", \"sigmoid\"]},\n \"degree\": {\"_type\": \"choice\", \"_value\": [1, 2, 3, 4]},\n \"gamma\": {\"_type\": \"quniform\", \"_value\": [0.01, 0.1, 0.01]},\n \"coef0\": {\"_type\": \"quniform\", \"_value\": [0.01, 0.1, 0.01]}\n}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configure Experiment\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from nni.experiment import Experiment\nexperiment = Experiment('local')\nexperiment.config.experiment_name = 'Example'\nexperiment.config.trial_concurrency = 2\nexperiment.config.max_trial_number = 10\nexperiment.config.search_space = search_space\nexperiment.config.trial_command = 'python scripts/trial_sklearn.py'\nexperiment.config.trial_code_directory = './'\nexperiment.config.tuner.name = 'TPE'\nexperiment.config.tuner.class_args['optimize_mode'] = 'maximize'\nexperiment.config.training_service.use_active_gpu = True"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Start Experiment\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"experiment.start(8080)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Experiment View & Control\n\nView the status of experiment.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"experiment.get_status()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Wait until at least one trial finishes.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import time\n\nfor _ in range(10):\n stats = experiment.get_job_statistics()\n if any(stat['trialJobStatus'] == 'SUCCEEDED' for stat in stats):\n break\n time.sleep(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Export the experiment data.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"experiment.export_data()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get metric of jobs\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"experiment.get_job_metrics()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Stop Experiment\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"experiment.stop()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
\ No newline at end of file
"""
Start and Manage a New Experiment
=================================
"""
# %%
# Configure Search Space
# ----------------------
search_space = {
"C": {"_type": "quniform", "_value": [0.1, 1, 0.1]},
"kernel": {"_type": "choice", "_value": ["linear", "rbf", "poly", "sigmoid"]},
"degree": {"_type": "choice", "_value": [1, 2, 3, 4]},
"gamma": {"_type": "quniform", "_value": [0.01, 0.1, 0.01]},
"coef0": {"_type": "quniform", "_value": [0.01, 0.1, 0.01]}
}
# %%
# Configure Experiment
# --------------------
from nni.experiment import Experiment
experiment = Experiment('local')
experiment.config.experiment_name = 'Example'
experiment.config.trial_concurrency = 2
experiment.config.max_trial_number = 10
experiment.config.search_space = search_space
experiment.config.trial_command = 'python scripts/trial_sklearn.py'
experiment.config.trial_code_directory = './'
experiment.config.tuner.name = 'TPE'
experiment.config.tuner.class_args['optimize_mode'] = 'maximize'
experiment.config.training_service.use_active_gpu = True
# %%
# Start Experiment
# ----------------
experiment.start(8080)
# %%
# Experiment View & Control
# -------------------------
#
# View the status of experiment.
experiment.get_status()
# %%
# Wait until at least one trial finishes.
import time
for _ in range(10):
stats = experiment.get_job_statistics()
if any(stat['trialJobStatus'] == 'SUCCEEDED' for stat in stats):
break
time.sleep(10)
# %%
# Export the experiment data.
experiment.export_data()
# %%
# Get metric of jobs
experiment.get_job_metrics()
# %%
# Stop Experiment
# ---------------
experiment.stop()
9f822647d89f05264b70d1ae1c473be1
\ No newline at end of file
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorials/nni_experiment.py"
.. LINE NUMBERS ARE GIVEN BELOW.
.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here <sphx_glr_download_tutorials_nni_experiment.py>`
to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_tutorials_nni_experiment.py:
Start and Manage a New Experiment
=================================
.. GENERATED FROM PYTHON SOURCE LINES 7-9
Configure Search Space
----------------------
.. GENERATED FROM PYTHON SOURCE LINES 9-18
.. code-block:: default
search_space = {
"C": {"_type": "quniform", "_value": [0.1, 1, 0.1]},
"kernel": {"_type": "choice", "_value": ["linear", "rbf", "poly", "sigmoid"]},
"degree": {"_type": "choice", "_value": [1, 2, 3, 4]},
"gamma": {"_type": "quniform", "_value": [0.01, 0.1, 0.01]},
"coef0": {"_type": "quniform", "_value": [0.01, 0.1, 0.01]}
}
.. GENERATED FROM PYTHON SOURCE LINES 19-21
Configure Experiment
--------------------
.. GENERATED FROM PYTHON SOURCE LINES 21-34
.. code-block:: default
from nni.experiment import Experiment
experiment = Experiment('local')
experiment.config.experiment_name = 'Example'
experiment.config.trial_concurrency = 2
experiment.config.max_trial_number = 10
experiment.config.search_space = search_space
experiment.config.trial_command = 'python scripts/trial_sklearn.py'
experiment.config.trial_code_directory = './'
experiment.config.tuner.name = 'TPE'
experiment.config.tuner.class_args['optimize_mode'] = 'maximize'
experiment.config.training_service.use_active_gpu = True
.. GENERATED FROM PYTHON SOURCE LINES 35-37
Start Experiment
----------------
.. GENERATED FROM PYTHON SOURCE LINES 37-39
.. code-block:: default
experiment.start(8080)
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[2022-02-07 18:56:04] Creating experiment, Experiment ID: fl9vu67z
[2022-02-07 18:56:04] Starting web server...
[2022-02-07 18:56:05] Setting up...
[2022-02-07 18:56:05] Web UI URLs: http://127.0.0.1:8080 http://10.190.173.211:8080 http://172.17.0.1:8080 http://192.168.49.1:8080
.. GENERATED FROM PYTHON SOURCE LINES 40-44
Experiment View & Control
-------------------------
View the status of experiment.
.. GENERATED FROM PYTHON SOURCE LINES 44-46
.. code-block:: default
experiment.get_status()
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
'RUNNING'
.. GENERATED FROM PYTHON SOURCE LINES 47-48
Wait until at least one trial finishes.
.. GENERATED FROM PYTHON SOURCE LINES 48-56
.. code-block:: default
import time
for _ in range(10):
stats = experiment.get_job_statistics()
if any(stat['trialJobStatus'] == 'SUCCEEDED' for stat in stats):
break
time.sleep(10)
.. GENERATED FROM PYTHON SOURCE LINES 57-58
Export the experiment data.
.. GENERATED FROM PYTHON SOURCE LINES 58-60
.. code-block:: default
experiment.export_data()
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[TrialResult(parameter={'C': 0.9, 'kernel': 'rbf', 'degree': 4, 'gamma': 0.07, 'coef0': 0.03}, value=0.9733333333333334, trialJobId='dNOZt'), TrialResult(parameter={'C': 0.8, 'kernel': 'sigmoid', 'degree': 2, 'gamma': 0.01, 'coef0': 0.01}, value=0.9733333333333334, trialJobId='okYSD')]
.. GENERATED FROM PYTHON SOURCE LINES 61-62
Get metric of jobs
.. GENERATED FROM PYTHON SOURCE LINES 62-64
.. code-block:: default
experiment.get_job_metrics()
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
{'okYSD': [TrialMetricData(timestamp=1644227777089, trialJobId='okYSD', parameterId='1', type='FINAL', sequence=0, data=0.9733333333333334)], 'dNOZt': [TrialMetricData(timestamp=1644227777357, trialJobId='dNOZt', parameterId='0', type='FINAL', sequence=0, data=0.9733333333333334)]}
.. GENERATED FROM PYTHON SOURCE LINES 65-67
Stop Experiment
---------------
.. GENERATED FROM PYTHON SOURCE LINES 67-68
.. code-block:: default
experiment.stop()
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[2022-02-07 18:56:25] Stopping experiment, please wait...
[2022-02-07 18:56:28] Experiment stopped
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 24.662 seconds)
.. _sphx_glr_download_tutorials_nni_experiment.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: nni_experiment.py <nni_experiment.py>`
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: nni_experiment.ipynb <nni_experiment.ipynb>`
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
......@@ -18,8 +18,6 @@ Computation times
+-----------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_tutorials_nasbench_as_dataset.py` (``nasbench_as_dataset.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_tutorials_nni_experiment.py` (``nni_experiment.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_tutorials_pruning_customize.py` (``pruning_customize.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_tutorials_quantization_customize.py` (``quantization_customize.py``) | 00:00.000 | 0.0 MB |
......
import argparse
import m2r
import os
import re
import shutil
from pathlib import Path
def single_line_process(line):
if line == ' .. contents::':
return '.. contents::'
# https://github.com/sphinx-doc/sphinx/issues/3921
line = re.sub(r'(`.*? <.*?>`)_', r'\1__', line)
# inline emphasis
line = re.sub(r'\*\*\\ (.*?)\\ \*\*', r' **\1** ', line)
line = re.sub(r'\*(.*?)\\ \*', r'*\1*', line)
line = re.sub(r'\*\*(.*?) \*\*', r'**\1** ', line)
line = re.sub(r'\\\*\\\*(.*?)\*\*', r'**\1**', line)
line = re.sub(r'\\\*\\\*(.*?)\*\*\\ ', r'**\1**', line)
line = line.replace(r'\* - `\**', r'* - `**')
line = re.sub(r'\\\* \*\*(.*?)\*\* \(\\\*\s*(.*?)\s*\*\\ \)', r'* \1 (\2)', line)
line = re.sub(r'\<(.*)\.md(\>|#)', r'<\1.rst\2', line)
line = re.sub(r'`\*\*(.*?)\*\* <#(.*?)>`__', r'`\1 <#\2>`__', line)
line = re.sub(r'\*\* (classArgs|stop|FLOPS.*?|pruned.*?|large.*?|path|pythonPath|2D.*?|codeDirectory|ps|worker|Tuner|Assessor)\*\*',
r' **\1**', line)
line = line.replace('.. code-block:::: bash', '.. code-block:: bash')
line = line.replace('raw-html-m2r', 'raw-html')
line = line.replace('[toc]', '.. toctree::')
# image
line = re.sub(r'\:raw\-html\:`\<img src\=\"(.*?)\" style\=\"zoom\: ?(\d+)\%\;\" \/\>`', r'\n.. image:: \1\n :scale: \2%', line)
# special case (per line handling)
line = line.replace('Nb = |Db|', r'Nb = \|Db\|')
line = line.replace(' Here is just a small list of libraries ', '\nHere is just a small list of libraries ')
line = line.replace(' Find the data management region in job submission page.', 'Find the data management region in job submission page.')
line = line.replace('Tuner/InstallCustomizedTuner.md', 'Tuner/InstallCustomizedTuner')
line = line.replace('&#10003;', ':raw-html:`&#10003;`')
line = line.replace(' **builtinTunerName** and** classArgs**', '**builtinTunerName** and **classArgs**')
line = line.replace('`\ ``nnictl ss_gen`` <../Tutorial/Nnictl.rst>`__', '`nnictl ss_gen <../Tutorial/Nnictl.rst>`__')
line = line.replace('**Step 1. Install NNI, follow the install guide `here <../Tutorial/QuickStart.rst>`__.**',
'**Step 1. Install NNI, follow the install guide** `here <../Tutorial/QuickStart.rst>`__.')
line = line.replace('*Please refer to `here ', 'Please refer to `here ')
# line = line.replace('\* **optimize_mode** ', '* **optimize_mode** ')
if line == '~' * len(line):
line = '^' * len(line)
return line
def special_case_replace(full_text):
replace_pairs = {}
replace_pairs['PyTorch\n"""""""'] = '**PyTorch**'
replace_pairs['Search Space\n============'] = '.. role:: raw-html(raw)\n :format: html\n\nSearch Space\n============'
for file in os.listdir(Path(__file__).parent / 'patches'):
with open(Path(__file__).parent / 'patches' / file) as f:
r, s = f.read().split('%%%%%%\n')
replace_pairs[r] = s
for r, s in replace_pairs.items():
full_text = full_text.replace(r, s)
return full_text
def process_table(content):
content = content.replace('------ |', '------|')
lines = []
for line in content.split('\n'):
if line.startswith(' |'):
line = line[2:]
lines.append(line)
return '\n'.join(lines)
def process_github_link(line):
line = re.sub(r'`(\\ ``)?([^`]*?)(``)? \<(.*?)(blob|tree)/v1.9/(.*?)\>`__', r':githublink:`\2 <\6>`', line)
if 'githublink' in line:
line = re.sub(r'\*Example: (.*)\*', r'*Example:* \1', line)
line = line.replace('https://nni.readthedocs.io/en/latest', '')
return line
for root, dirs, files in os.walk('en_US'):
root = Path(root)
for file in files:
if not file.endswith('.md') or file == 'Release_v1.0.md':
continue
with open(root / file) as f:
md_content = f.read()
if file == 'Nnictl.md':
md_content = process_table(md_content)
out = m2r.convert(md_content)
lines = out.split('\n')
if lines[0] == '':
lines = lines[1:]
# remove code-block eval_rst
i = 0
while i < len(lines):
line = lines[i]
if line.strip() == '.. code-block:: eval_rst':
space_count = line.index('.')
lines[i] = lines[i + 1] = None
if i > 0 and lines[i - 1]:
lines[i] = '' # blank line
i += 2
while i < len(lines) and (lines[i].startswith(' ' * (space_count + 3)) or lines[i] == ''):
lines[i] = lines[i][space_count + 3:]
i += 1
elif line.strip() == '.. code-block' or line.strip() == '.. code-block::':
lines[i] += ':: bash'
i += 1
else:
i += 1
lines = [l for l in lines if l is not None]
lines = list(map(single_line_process, lines))
if file != 'Release.md':
# githublink
lines = list(map(process_github_link, lines))
out = '\n'.join(lines)
out = special_case_replace(out)
with open(root / (Path(file).stem + '.rst'), 'w') as f:
f.write(out)
# back it up and remove
moved_root = Path('archive_en_US') / root.relative_to('en_US')
moved_root.mkdir(exist_ok=True)
shutil.move(root / file, moved_root / file)
* - GP Tuner
- :raw-html:`&#10003;`
-
- :raw-html:`&#10003;`
- :raw-html:`&#10003;`
- :raw-html:`&#10003;`
- :raw-html:`&#10003;`
- :raw-html:`&#10003;`
-
-
-
%%%%%%
* - GP Tuner
- :raw-html:`&#10003;`
-
- :raw-html:`&#10003;`
- :raw-html:`&#10003;`
- :raw-html:`&#10003;`
- :raw-html:`&#10003;`
- :raw-html:`&#10003;`
-
-
-
-
An SSH server needs a port; you need to expose Docker's SSH port to NNI as the connection port. For example, if you set your container's SSH port as **``A``** \ , you should map the container's port ** ``A``** to your remote host machine's other port ** ``B``** \ , NNI will connect port ** ``B``** as an SSH port, and your host machine will map the connection from port ** ``B``** to port ** ``A``** then NNI could connect to your Docker container.
%%%%%%
An SSH server needs a port; you need to expose Docker's SSH port to NNI as the connection port. For example, if you set your container's SSH port as ``A``, you should map the container's port ``A`` to your remote host machine's other port ``B``, NNI will connect port ``B`` as an SSH port, and your host machine will map the connection from port ``B`` to port ``A`` then NNI could connect to your Docker container.
If the id ends with *, nnictl will stop all experiments whose ids matchs the regular.
%%%%%%
If the id ends with \*, nnictl will stop all experiments whose ids matchs the regular.
..
make: *** [install-XXX] Segmentation fault (core dumped)
%%%%%%
.. code-block:: text
make: *** [install-XXX] Segmentation fault (core dumped)
Click ``Submit job`` button in web portal.
%%%%%%
Click ``Submit job`` button in web portal.
:raw-html:`<div >
<img src="https://github.com/microsoft/Cream/blob/main/demo/intro.jpg" width="800"/>
</div>`
%%%%%%
:raw-html:`<div ><img src="https://github.com/microsoft/Cream/blob/main/demo/intro.jpg" width="800"/></div>`
\ No newline at end of file
.. list-table::
:header-rows: 1
%%%%%%
.. list-table::
:header-rows: 1
:widths: auto
.. code-block:: bash
1.1 Declare NNI API
Include `import nni` in your trial code to use NNI APIs.
%%%%%%
..
1.1 Declare NNI API
Include `import nni` in your trial code to use NNI APIs.
.. code-block:: bash
from nni.compression.pytorch.utils.counter import count_flops_params
%%%%%%
.. code-block:: python
from nni.compression.pytorch.utils.counter import count_flops_params
.. code-block:: bash
NNI's official image msranni/nni does not support SSH servers for the time being; you should build your own Docker image with an SSH configuration or use other images as a remote server.
%%%%%%
.. code-block:: text
NNI's official image msranni/nni does not support SSH servers for the time being; you should build your own Docker image with an SSH configuration or use other images as a remote server.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment