Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
abd164c2
Unverified
Commit
abd164c2
authored
Feb 10, 2022
by
Yuge Zhang
Committed by
GitHub
Feb 10, 2022
Browse files
Bootstrapping tutorials in documentation (#4522)
parent
cc122226
Changes
368
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
183 additions
and
8 deletions
+183
-8
docs/zh_CN/nnSpider/weaving.rst
docs/zh_CN/nnSpider/weaving.rst
+0
-1
docs/zh_CN/nnSpider/working.rst
docs/zh_CN/nnSpider/working.rst
+0
-1
docs/zh_CN/reference/experiment_config.rst
docs/zh_CN/reference/experiment_config.rst
+0
-1
examples/tutorials/README.rst
examples/tutorials/README.rst
+2
-0
examples/tutorials/nas_quick_start_mnist.py
examples/tutorials/nas_quick_start_mnist.py
+11
-0
examples/tutorials/nni_experiment.py
examples/tutorials/nni_experiment.py
+67
-0
examples/tutorials/scripts/trial_sklearn.py
examples/tutorials/scripts/trial_sklearn.py
+88
-0
pipelines/fast-test.yml
pipelines/fast-test.yml
+15
-5
No files found.
docs/zh_CN/nnSpider/weaving.rst
deleted
120000 → 0
View file @
cc122226
../../en_US/nnSpider/weaving.rst
\ No newline at end of file
docs/zh_CN/nnSpider/working.rst
deleted
120000 → 0
View file @
cc122226
../../en_US/nnSpider/working.rst
\ No newline at end of file
docs/zh_CN/reference/experiment_config.rst
deleted
120000 → 0
View file @
cc122226
../../en_US/reference/experiment_config.rst
\ No newline at end of file
examples/tutorials/README.rst
0 → 100644
View file @
abd164c2
Tutorials
=========
examples/tutorials/nas_quick_start_mnist.py
0 → 100644
View file @
abd164c2
"""
Get started with NAS on MNIST
=============================
"""
# %%
a
=
(
1
,
2
,
3
)
a
# %%
print
(
'hello'
)
examples/tutorials/nni_experiment.py
0 → 100644
View file @
abd164c2
"""
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
()
examples/tutorials/scripts/trial_sklearn.py
0 → 100644
View file @
abd164c2
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import
nni
from
sklearn.model_selection
import
train_test_split
from
sklearn.datasets
import
load_digits
from
sklearn.preprocessing
import
StandardScaler
from
sklearn.svm
import
SVC
import
logging
import
numpy
as
np
LOG
=
logging
.
getLogger
(
'sklearn_classification'
)
def
load_data
():
"""Load dataset, use 20newsgroups dataset"""
digits
=
load_digits
()
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
digits
.
data
,
digits
.
target
,
random_state
=
99
,
test_size
=
0.25
)
ss
=
StandardScaler
()
X_train
=
ss
.
fit_transform
(
X_train
)
X_test
=
ss
.
transform
(
X_test
)
return
X_train
,
X_test
,
y_train
,
y_test
def
get_default_parameters
():
"""get default parameters"""
params
=
{
'C'
:
1.0
,
'kernel'
:
'linear'
,
'degree'
:
3
,
'gamma'
:
0.01
,
'coef0'
:
0.01
}
return
params
def
get_model
(
PARAMS
):
"""Get model according to parameters"""
model
=
SVC
()
model
.
C
=
PARAMS
.
get
(
'C'
)
model
.
kernel
=
PARAMS
.
get
(
'kernel'
)
model
.
degree
=
PARAMS
.
get
(
'degree'
)
model
.
gamma
=
PARAMS
.
get
(
'gamma'
)
model
.
coef0
=
PARAMS
.
get
(
'coef0'
)
return
model
def
run
(
X_train
,
X_test
,
y_train
,
y_test
,
model
):
"""Train model and predict result"""
model
.
fit
(
X_train
,
y_train
)
score
=
model
.
score
(
X_test
,
y_test
)
LOG
.
debug
(
'score: %s'
,
score
)
nni
.
report_final_result
(
score
)
if
__name__
==
'__main__'
:
X_train
,
X_test
,
y_train
,
y_test
=
load_data
()
try
:
# get parameters from tuner
RECEIVED_PARAMS
=
nni
.
get_next_parameter
()
LOG
.
debug
(
RECEIVED_PARAMS
)
PARAMS
=
get_default_parameters
()
PARAMS
.
update
(
RECEIVED_PARAMS
)
LOG
.
debug
(
PARAMS
)
model
=
get_model
(
PARAMS
)
run
(
X_train
,
X_test
,
y_train
,
y_test
,
model
)
except
Exception
as
exception
:
LOG
.
exception
(
exception
)
raise
pipelines/fast-test.yml
View file @
abd164c2
...
...
@@ -20,13 +20,23 @@ stages:
-
script
:
|
cd docs
python tools/chineselink.py check
displayName
:
Translation up-to-date
# rstcheck -r source
displayName
:
rstcheck (disabled for now)
# TODO: rstcheck
-
script
:
|
cd docs
make -e SPHINXOPTS="-W --keep-going -T" html
displayName
:
Sphinx sanity check
-
script
:
|
cd docs/en_US
sphinx-build -M html . _build -W --keep-going -T
displayName
:
Sphinx
# TODO: rstcheck
cd docs
make -e SPHINXOPTS="-W --keep-going -T -D language='zh'" html
displayName
:
Sphinx sanity check (Chinese)
-
script
:
|
cd docs
python tools/chineselink.py check
displayName
:
Translation up-to-date
-
job
:
python
pool
:
...
...
Prev
1
…
15
16
17
18
19
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment