Skip to content

Commit 2ca6258

Browse files
mattseddondaavoo
andauthored
Add DVCLive snippets (#4258)
Co-authored-by: David de la Iglesia Castro <[email protected]>
1 parent 9c546ea commit 2ca6258

File tree

8 files changed

+158
-28
lines changed

8 files changed

+158
-28
lines changed

extension/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,10 @@
13991399
{
14001400
"language": "yaml",
14011401
"path": "./snippets/dvc-yaml.code-snippets"
1402+
},
1403+
{
1404+
"language": "python",
1405+
"path": "./snippets/dvclive.code-snippets"
14021406
}
14031407
],
14041408
"viewsContainers": {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"DVCLive Catalyst": {
3+
"prefix": "dvclive-catalyst",
4+
"body": [
5+
"from dvclive.catalyst import DVCLiveCallback",
6+
"",
7+
"runner.train(",
8+
" model=${1:model}, criterion=${2:criterion}, optimizer=${3:optimizer}, loaders=${4:loaders},",
9+
" callbacks=[DVCLiveCallback()])"
10+
],
11+
"description": "DVCLive Catalyst callback"
12+
},
13+
"DVCLive Fast.ai": {
14+
"prefix": "dvclive-fastai",
15+
"body": [
16+
"from dvclive.fastai import DVCLiveCallback",
17+
"",
18+
"learn.fit_one_cycle(",
19+
" n_epoch=${3:2},",
20+
" cbs=[DVCLiveCallback()])"
21+
],
22+
"description": "DVCLive Fast.ai callback"
23+
},
24+
"DVCLive Hugging Face": {
25+
"prefix": "dvclive-huggingface",
26+
"body": [
27+
"from dvclive.huggingface import DVCLiveCallback",
28+
"",
29+
"trainer = Trainer(",
30+
" ${1:model}, ${2:args},",
31+
" train_dataset=${3:train_data},",
32+
" eval_dataset=${4:eval_data},",
33+
" tokenizer=${5:tokenizer},",
34+
" compute_metrics=${6:compute_metrics},",
35+
")",
36+
"trainer.add_callback(DVCLiveCallback(save_dvc_exp=True))",
37+
"trainer.train()"
38+
],
39+
"description": "DVCLive Hugging Face callback"
40+
},
41+
"DVCLive Keras": {
42+
"prefix": "dvclive-keras",
43+
"body": [
44+
"from dvclive.keras import DVCLiveCallback",
45+
"",
46+
"model.fit(",
47+
" ${1:train_dataset}, epochs=${2:num_epochs}, validation_data=${3:validation_dataset},",
48+
" callbacks=[DVCLiveCallback(save_dvc_exp=True)])"
49+
],
50+
"description": "DVCLive Keras callback"
51+
},
52+
"DVCLive LightGBM": {
53+
"prefix": "dvclive-lightgbm",
54+
"body": [
55+
"from dvclive.lgbm import DVCLiveCallback",
56+
"",
57+
"lightgbm.train(",
58+
" ${1:param}, ${2:train_data}, valid_sets=[${3:validation_data}], num_round=${4:5},",
59+
" callbacks=[DVCLiveCallback(save_dvc_exp=True)])"
60+
],
61+
"description": "DVCLive LightGBM callback"
62+
},
63+
"DVCLive Optuna": {
64+
"prefix": "dvclive-optuna",
65+
"body": [
66+
"from dvclive.optuna import DVCLiveCallback",
67+
"",
68+
"study.optimize(",
69+
" ${1:objective}, n_trials=${2:7}, callbacks=[DVCLiveCallback()])"
70+
],
71+
"description": "DVCLive Optuna callback"
72+
},
73+
"DVCLive Pytorch Lightning": {
74+
"prefix": "dvclive-pytorch-lightning",
75+
"body": [
76+
"import lightning.pytorch as pl",
77+
"from dvclive.lightning import DVCLiveLogger",
78+
"",
79+
"class LitModule(pl.LightningModule):",
80+
" def __init__(self, layer_1_dim=${1:128}, learning_rate=${2:1e-2}):",
81+
" super().__init__()",
82+
" # layer_1_dim and learning_rate will be logged by DVCLive",
83+
" self.save_hyperparameters()",
84+
"",
85+
" def training_step(self, batch, batch_idx):",
86+
" metric = ${3:...}",
87+
" # See Output Format bellow",
88+
" self.log(${4:\"train_metric\"}, ${5:metric}, on_step=${6:False}, on_epoch=${7:True})",
89+
"",
90+
"dvclive_logger = DVCLiveLogger(save_dvc_exp=True)",
91+
"",
92+
"model = LitModule()",
93+
"trainer = pl.Trainer(logger=dvclive_logger)",
94+
"trainer.fit(model)"
95+
],
96+
"description": "DVCLive Pytorch Lightning example"
97+
},
98+
"DVCLive XGBoost": {
99+
"prefix": "dvclive-xgboost",
100+
"body": [
101+
"from dvclive.xgb import DVCLiveCallback",
102+
"",
103+
"xgboost.train(",
104+
" ${1:param}, ${2:dtrain}, num_round=${3:5}, evals=[${4:(dval, \"eval_data\")}]",
105+
" callbacks=[DVCLiveCallback(${5:\"eval_data\"}, save_dvc_exp=True)],",
106+
")"
107+
],
108+
"description": "DVCLive XGBoost callback"
109+
}
110+
}

webview/src/setup/components/experiments/DvcLiveExamples.tsx

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,46 @@ import keras from '../../snippets/keras.py'
88
import pythonApi from '../../snippets/pythonApi.py'
99
import { CodeBlock } from '../shared/CodeBlock'
1010
import { Panels } from '../shared/Panels'
11+
import { InfoText } from '../shared/InfoText'
1112

1213
const PythonCodeBlock = ({ children }: { children: string }) => (
1314
<CodeBlock language="python">{children}</CodeBlock>
1415
)
1516

1617
export const DvcLiveExamples: React.FC = () => {
1718
return (
18-
<Panels
19-
className={styles.dvcLiveExamples}
20-
panels={[
21-
{
22-
children: <PythonCodeBlock>{pythonApi.toString()}</PythonCodeBlock>,
23-
title: 'Python API'
24-
},
25-
{
26-
children: <PythonCodeBlock>{pyTorch.toString()}</PythonCodeBlock>,
27-
title: 'PyTorch Lightning'
28-
},
29-
{
30-
children: <PythonCodeBlock>{huggingFace.toString()}</PythonCodeBlock>,
31-
title: 'Hugging Face'
32-
},
33-
{
34-
children: <PythonCodeBlock>{keras.toString()}</PythonCodeBlock>,
35-
title: 'Keras'
36-
},
37-
{
38-
children: <OtherFrameworks />,
39-
title: 'Other'
40-
}
41-
]}
42-
/>
19+
<>
20+
<Panels
21+
className={styles.dvcLiveExamples}
22+
panels={[
23+
{
24+
children: <PythonCodeBlock>{pythonApi.toString()}</PythonCodeBlock>,
25+
title: 'Python API'
26+
},
27+
{
28+
children: <PythonCodeBlock>{pyTorch.toString()}</PythonCodeBlock>,
29+
title: 'PyTorch Lightning'
30+
},
31+
{
32+
children: (
33+
<PythonCodeBlock>{huggingFace.toString()}</PythonCodeBlock>
34+
),
35+
title: 'Hugging Face'
36+
},
37+
{
38+
children: <PythonCodeBlock>{keras.toString()}</PythonCodeBlock>,
39+
title: 'Keras'
40+
},
41+
{
42+
children: <OtherFrameworks />,
43+
title: 'Other'
44+
}
45+
]}
46+
/>
47+
<InfoText>
48+
DVCLive snippets are provided for most frameworks. Type dvclive- in a
49+
Python file to see the full list.
50+
</InfoText>
51+
</>
4352
)
4453
}

webview/src/setup/components/remotes/AmazonS3.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import styles from './styles.module.scss'
3-
import { InfoText } from './InfoText'
43
import { ShowExtension } from './ShowExtension'
4+
import { InfoText } from '../shared/InfoText'
55

66
export const AmazonS3 = () => (
77
<div className={styles.storageDetails}>

webview/src/setup/components/remotes/ShowExtension.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const ShowExtension: React.FC<{
1616
icon={Extensions}
1717
width={16}
1818
height={16}
19-
className={styles.infoIcon}
19+
className={styles.extensionIcon}
2020
/>{' '}
2121
The <ExtensionLink extensionId={id}>{name}</ExtensionLink> extension can
2222
be used to <span>{capabilities}</span>.

webview/src/setup/components/remotes/styles.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
width: max-content;
5656
}
5757

58-
.infoIcon {
58+
.extensionIcon {
5959
fill: $accent-color;
6060
margin-bottom: -3px;
6161
}

webview/src/setup/components/shared/styles.module.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import '../../../shared/variables';
2+
13
.codeBlock {
24
text-align: left;
35
padding: 10px;
@@ -12,3 +14,8 @@
1214
padding: 0;
1315
min-width: 0;
1416
}
17+
18+
.infoIcon {
19+
fill: $accent-color;
20+
margin-bottom: -3px;
21+
}

0 commit comments

Comments
 (0)