Skip to content

Commit d12cd3a

Browse files
authored
Introducing Python-Fire in the Code-Generator as a config management system (#300)
* Add changes for python fire in the code-generator * Reformatting run_tests.sh files and CI accordingly * Removed argparser twice in TrainingTab.vue and empty lines in commit * fmt fix * dist_lint fix * Change the dist_lint in run_code_style.sh and ci accordingly * fix formatting and bugs
1 parent 9e73964 commit d12cd3a

File tree

18 files changed

+270
-24
lines changed

18 files changed

+270
-24
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ jobs:
8787
run: pnpm test:ci
8888

8989
- run: sh ./scripts/run_tests.sh unzip
90-
- run: pnpm dist_lint ${{ matrix.template }}
90+
- run: pnpm dist_lint ${{ matrix.template }} argparse
91+
- run: pnpm dist_lint ${{ matrix.template }} fire
9192

9293
- name: 'Run ${{ matrix.template }} ${{ matrix.test }}'
93-
run: sh ./scripts/run_tests.sh ${{ matrix.test }} ${{ matrix.template }}
94+
run: sh ./scripts/run_tests.sh ${{ matrix.test }} ${{ matrix.template }} argparse
95+
96+
- name: 'Run ${{ matrix.template }} ${{ matrix.test }} - Python Fire'
97+
run: sh ./scripts/run_tests.sh ${{ matrix.test }} ${{ matrix.template }} fire
9498

9599
lint:
96100
runs-on: ubuntu-latest

__tests__/text-classification.spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ afterEach(async () => {
2424
await context.close()
2525
})
2626

27-
const parser = ['argparse']
27+
const parser = ['argparse', 'fire']
2828
for (const name of parser) {
2929
test(`text-classification simple ${name}`, async () => {
3030
await page.selectOption('select', 'template-text-classification')
@@ -35,6 +35,11 @@ for (const name of parser) {
3535
await page.click('text=config.yaml')
3636
await page.getByText('Training', { exact: true }).click()
3737

38+
await page
39+
.getByRole('combobox', {
40+
name: 'Select the argument parser for training'
41+
})
42+
.selectOption(`${name}`)
3843
// TODO: simplify the downloadPromise calls
3944
// Here we are trying to wait for 2 seconds before clicking on the `Code` and `Download Zip` button
4045
const downloadPromise = await page
@@ -69,6 +74,11 @@ for (const name of parser) {
6974

7075
await page.waitForSelector('text=README.md')
7176
await page.getByText('Training', { exact: true }).click()
77+
await page
78+
.getByRole('combobox', {
79+
name: 'Select the argument parser for training'
80+
})
81+
.selectOption(`${name}`)
7282
await page.check('#deterministic-checkbox')
7383
expect(await page.isChecked('#deterministic-checkbox')).toBeTruthy()
7484

@@ -135,6 +145,11 @@ for (const name of parser) {
135145
await page.waitForSelector('text=README.md')
136146
await page.getByText('Training', { exact: true }).click()
137147

148+
await page
149+
.getByRole('combobox', {
150+
name: 'Select the argument parser for training'
151+
})
152+
.selectOption(`${name}`)
138153
await page.check('#use_dist-checkbox')
139154
expect(await page.isChecked('#use_dist-checkbox')).toBeTruthy()
140155

@@ -171,6 +186,11 @@ for (const name of parser) {
171186

172187
await page.waitForSelector('text=README.md')
173188
await page.getByText('Training', { exact: true }).click()
189+
await page
190+
.getByRole('combobox', {
191+
name: 'Select the argument parser for training'
192+
})
193+
.selectOption(`${name}`)
174194
await page.check('#use_dist-checkbox')
175195
expect(await page.isChecked('#use_dist-checkbox')).toBeTruthy()
176196

__tests__/vision-classification.spec.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ afterEach(async () => {
2424
await context.close()
2525
})
2626

27-
const parser = ['argparse']
27+
const parser = ['argparse', 'fire']
2828
for (const name of parser) {
2929
test(`vision-classification simple ${name}`, async () => {
3030
await page.selectOption('select', 'template-vision-classification')
@@ -35,6 +35,12 @@ for (const name of parser) {
3535
await page.click('text=config.yaml')
3636
await page.getByText('Training', { exact: true }).click()
3737

38+
await page
39+
.getByRole('combobox', {
40+
name: 'Select the argument parser for training'
41+
})
42+
.selectOption(`${name}`)
43+
3844
// TODO: simplify the downloadPromise calls
3945
// Here we are trying to wait for 2 seconds before clicking on the `Code` and `Download Zip` button
4046
const downloadPromise = await page
@@ -69,6 +75,11 @@ for (const name of parser) {
6975

7076
await page.waitForSelector('text=README.md')
7177
await page.getByText('Training', { exact: true }).click()
78+
await page
79+
.getByRole('combobox', {
80+
name: 'Select the argument parser for training'
81+
})
82+
.selectOption(`${name}`)
7283
await page.check('#deterministic-checkbox')
7384
expect(await page.isChecked('#deterministic-checkbox')).toBeTruthy()
7485

@@ -134,6 +145,11 @@ for (const name of parser) {
134145

135146
await page.waitForSelector('text=README.md')
136147
await page.getByText('Training', { exact: true }).click()
148+
await page
149+
.getByRole('combobox', {
150+
name: 'Select the argument parser for training'
151+
})
152+
.selectOption(`${name}`)
137153
await page.check('#use_dist-checkbox')
138154
expect(await page.isChecked('#use_dist-checkbox')).toBeTruthy()
139155

@@ -169,6 +185,12 @@ for (const name of parser) {
169185

170186
await page.waitForSelector('text=README.md')
171187
await page.getByText('Training', { exact: true }).click()
188+
await page
189+
.getByRole('combobox', {
190+
name: 'Select the argument parser for training'
191+
})
192+
.selectOption(`${name}`)
193+
172194
await page.check('#use_dist-checkbox')
173195
expect(await page.isChecked('#use_dist-checkbox')).toBeTruthy()
174196

__tests__/vision-dcgan.spec.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ afterEach(async () => {
2424
await context.close()
2525
})
2626

27-
const parser = ['argparse']
27+
const parser = ['argparse', 'fire']
2828
for (const name of parser) {
2929
test(`vision-dcgan simple ${name}`, async () => {
3030
await page.selectOption('select', 'template-vision-dcgan')
@@ -35,6 +35,11 @@ for (const name of parser) {
3535
await page.click('text=config.yaml')
3636
await page.getByText('Training', { exact: true }).click()
3737

38+
await page
39+
.getByRole('combobox', {
40+
name: 'Select the argument parser for training'
41+
})
42+
.selectOption(`${name}`)
3843
// TODO: simplify the downloadPromise calls
3944
// Here we are trying to wait for 2 seconds before clicking on the `Code` and `Download Zip` button
4045
const downloadPromise = await page
@@ -66,6 +71,11 @@ for (const name of parser) {
6671

6772
await page.waitForSelector('text=README.md')
6873
await page.getByText('Training', { exact: true }).click()
74+
await page
75+
.getByRole('combobox', {
76+
name: 'Select the argument parser for training'
77+
})
78+
.selectOption(`${name}`)
6979
await page.check('#deterministic-checkbox')
7080
expect(await page.isChecked('#deterministic-checkbox')).toBeTruthy()
7181

@@ -129,6 +139,11 @@ for (const name of parser) {
129139

130140
await page.waitForSelector('text=README.md')
131141
await page.getByText('Training', { exact: true }).click()
142+
await page
143+
.getByRole('combobox', {
144+
name: 'Select the argument parser for training'
145+
})
146+
.selectOption(`${name}`)
132147
await page.check('#use_dist-checkbox')
133148
expect(await page.isChecked('#use_dist-checkbox')).toBeTruthy()
134149

__tests__/vision-segmentation.spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ afterEach(async () => {
2424
await context.close()
2525
})
2626

27-
const parser = ['argparse']
27+
const parser = ['argparse', 'fire']
2828
for (const name of parser) {
2929
test(`vision-segmentation simple ${name}`, async () => {
3030
await page.selectOption('select', 'template-vision-segmentation')
@@ -35,6 +35,11 @@ for (const name of parser) {
3535
await page.click('text=config.yaml')
3636
await page.getByText('Training', { exact: true }).click()
3737

38+
await page
39+
.getByRole('combobox', {
40+
name: 'Select the argument parser for training'
41+
})
42+
.selectOption(`${name}`)
3843
// TODO: simplify the downloadPromise calls
3944
// Here we are trying to wait for 2 seconds before clicking on the `Code` and `Download Zip` button
4045
const downloadPromise = await page
@@ -68,6 +73,11 @@ for (const name of parser) {
6873

6974
await page.waitForSelector('text=README.md')
7075
await page.getByText('Training', { exact: true }).click()
76+
await page
77+
.getByRole('combobox', {
78+
name: 'Select the argument parser for training'
79+
})
80+
.selectOption(`${name}`)
7181
await page.check('#deterministic-checkbox')
7282
expect(await page.isChecked('#deterministic-checkbox')).toBeTruthy()
7383

@@ -134,6 +144,11 @@ for (const name of parser) {
134144

135145
await page.waitForSelector('text=README.md')
136146
await page.getByText('Training', { exact: true }).click()
147+
await page
148+
.getByRole('combobox', {
149+
name: 'Select the argument parser for training'
150+
})
151+
.selectOption(`${name}`)
137152
await page.check('#use_dist-checkbox')
138153
expect(await page.isChecked('#use_dist-checkbox')).toBeTruthy()
139154

@@ -169,6 +184,11 @@ for (const name of parser) {
169184

170185
await page.waitForSelector('text=README.md')
171186
await page.getByText('Training', { exact: true }).click()
187+
await page
188+
.getByRole('combobox', {
189+
name: 'Select the argument parser for training'
190+
})
191+
.selectOption(`${name}`)
172192
await page.check('#use_dist-checkbox')
173193
expect(await page.isChecked('#use_dist-checkbox')).toBeTruthy()
174194

scripts/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ pytest
88
transformers
99
datasets
1010
tensorboard
11+
fire
1112
omegaconf

scripts/run_code_style.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ set -xeu
55
if [ $1 == "dist_lint" ]; then
66
# Check that ./dist-tests/ exists and code is unzipped
77
TEMP=${2:-vision-classification}
8+
ARGPARSE=${3:-argparse}
89

910
# for argparse
10-
ls ./dist-tests/$TEMP-all-argparse/main.py
11+
if [ "$ARGPARSE" == "argparse" ]; then
12+
ls ./dist-tests/$TEMP-all-argparse/main.py
13+
fi
1114

15+
# for python-fire
16+
if [ "$ARGPARSE" == "fire" ]; then
17+
ls ./dist-tests/$TEMP-all-fire/main.py
18+
fi
19+
1220
# Comment dist-tests in .gitignore to make black running on ./dist-tests folder
1321
sed -i "s/dist-tests/# dist-tests/g" .gitignore
1422

scripts/run_tests.sh

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ unzip_all() {
1414
done
1515
}
1616

17+
# Python-Argparser functions
18+
1719
run_simple() {
1820
for dir in $(find ./dist-tests/$1-simple-argparse -type d)
1921
do
@@ -51,14 +53,70 @@ run_spawn() {
5153
done
5254
}
5355

56+
# Python-fire functions
57+
58+
run_simple_fire() {
59+
for dir in $(find ./dist-tests/$1-simple-fire -type d)
60+
do
61+
cd $dir
62+
python main.py ../../src/tests/ci-configs/$1-simple.yaml
63+
cd $CWD
64+
done
65+
}
66+
67+
run_all_fire() {
68+
for dir in $(find ./dist-tests/$1-all-fire -type d)
69+
do
70+
cd $dir
71+
pytest -vra --color=yes --tb=short test_*.py
72+
python main.py ../../src/tests/ci-configs/$1-all.yaml
73+
cd $CWD
74+
done
75+
}
76+
77+
run_launch_fire() {
78+
for dir in $(find ./dist-tests/$1-launch-fire -type d)
79+
do
80+
cd $dir
81+
torchrun --nproc_per_node 2 main.py ../../src/tests/ci-configs/$1-launch.yaml --backend gloo
82+
cd $CWD
83+
done
84+
}
85+
86+
run_spawn_fire() {
87+
for dir in $(find ./dist-tests/$1-spawn-fire -type d)
88+
do
89+
cd $dir
90+
python main.py ../../src/tests/ci-configs/$1-spawn.yaml --backend gloo
91+
cd $CWD
92+
done
93+
}
94+
95+
5496
if [ $1 = "unzip" ]; then
5597
unzip_all
5698
elif [ $1 = "simple" ]; then
57-
run_simple $2
99+
if [ $3 = "argparse" ]; then
100+
run_simple $2
101+
elif [ $3 = "fire" ]; then
102+
run_simple_fire $2
103+
fi
58104
elif [ $1 = "all" ]; then
59-
run_all $2
105+
if [ $3 = "argparse" ]; then
106+
run_all $2
107+
elif [ $3 = "fire" ]; then
108+
run_all_fire $2
109+
fi
60110
elif [ $1 = "launch" ]; then
61-
run_launch $2
111+
if [ $3 = "argparse" ]; then
112+
run_launch $2
113+
elif [ $3 = "fire" ]; then
114+
run_launch_fire $2
115+
fi
62116
elif [ $1 = "spawn" ]; then
63-
run_spawn $2
117+
if [ $3 = "argparse" ]; then
118+
run_spawn $2
119+
elif [ $3 = "fire" ]; then
120+
run_spawn_fire $2
121+
fi
64122
fi

src/components/TabTraining.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
<a href="https://docs.python.org/3/library/argparse.html">Argparse</a> -
1414
is a python built-in tool to handle command-line arguments
1515
</li>
16+
<li>
17+
<a
18+
href="https://github.com/google/python-fire/blob/master/docs/guide.md"
19+
>Python Fire</a
20+
>
21+
- transforms Python functions into user-friendly command-line tools,
22+
ideal for DL experimentation.
23+
</li>
1624
</ul>
1725
<FormSelect
1826
:label="argparser.description"

src/metadata/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "argparser",
55
"type": "array",
66
"description": "Select the argument parser for training",
7-
"options": ["argparse"],
7+
"options": ["argparse", "fire"],
88
"default": "argparse"
99
},
1010
"deterministic": {

0 commit comments

Comments
 (0)