Skip to content

Commit 806abf8

Browse files
authored
Added Hydra support as an option in ArgParse UI (#302)
* Introducing Hydra in Code-generator * Made some bug fixes and CI changes * Add changes to colab functions for Hydra * fix bug in colab.js * fix bugs in utils.py * Removed unnecessay code in setup_config for hydra * changed colab function behaviour when argparser = hydra * fixed colab output * changed the argparser due to undefined output * final change, removing debug output * Fix bugs for Hydra output-dir and overiding the config files
1 parent df76bf1 commit 806abf8

File tree

20 files changed

+199
-17
lines changed

20 files changed

+199
-17
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@ jobs:
8484
- run: sh ./scripts/run_tests.sh unzip
8585
- run: pnpm dist_lint ${{ matrix.template }} argparse
8686
- run: pnpm dist_lint ${{ matrix.template }} fire
87+
- run: pnpm dist_lint ${{ matrix.template }} hydra
8788

8889
- name: 'Run ${{ matrix.template }} ${{ matrix.test }}'
8990
run: sh ./scripts/run_tests.sh ${{ matrix.test }} ${{ matrix.template }} argparse
9091

9192
- name: 'Run ${{ matrix.template }} ${{ matrix.test }} - Python Fire'
9293
run: sh ./scripts/run_tests.sh ${{ matrix.test }} ${{ matrix.template }} fire
9394

95+
- name: 'Run ${{ matrix.template }} ${{ matrix.test }} - Hydra'
96+
run: sh ./scripts/run_tests.sh ${{ matrix.test }} ${{ matrix.template }} hydra
97+
9498
lint:
9599
runs-on: ubuntu-latest
96100
steps:

__tests__/text-classification.spec.js

Lines changed: 1 addition & 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', 'fire']
27+
const parser = ['argparse', 'fire', 'hydra']
2828
for (const name of parser) {
2929
test(`text-classification simple ${name}`, async () => {
3030
await page.selectOption('select', 'template-text-classification')

__tests__/vision-classification.spec.js

Lines changed: 1 addition & 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', 'fire']
27+
const parser = ['argparse', 'fire', 'hydra']
2828
for (const name of parser) {
2929
test(`vision-classification simple ${name}`, async () => {
3030
await page.selectOption('select', 'template-vision-classification')

__tests__/vision-dcgan.spec.js

Lines changed: 1 addition & 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', 'fire']
27+
const parser = ['argparse', 'fire', 'hydra']
2828
for (const name of parser) {
2929
test(`vision-dcgan simple ${name}`, async () => {
3030
await page.selectOption('select', 'template-vision-dcgan')

__tests__/vision-segmentation.spec.js

Lines changed: 1 addition & 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', 'fire']
27+
const parser = ['argparse', 'fire', 'hydra']
2828
for (const name of parser) {
2929
test(`vision-segmentation simple ${name}`, async () => {
3030
await page.selectOption('select', 'template-vision-segmentation')

functions/colab.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ exports.handler = async function (event, _) {
4848
'!pip install -r requirements.txt'
4949
]
5050

51-
const execution_nb_commands = ['!python main.py config.yaml']
51+
const argparser = data.argparser
52+
const execution_nb_commands = [
53+
`!python main.py ${
54+
argparser === 'hydra'
55+
? '#--config-dir=/content/ --config-name=config.yaml'
56+
: 'config.yaml'
57+
}`
58+
]
5259

5360
let nb_cells = [
5461
create_nb_cell(md_cell, 'markdown'),

scripts/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ transformers
99
datasets
1010
tensorboard
1111
fire
12+
hydra-core
1213
omegaconf

scripts/run_code_style.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ if [ $1 == "dist_lint" ]; then
1717
ls ./dist-tests/$TEMP-all-fire/main.py
1818
fi
1919

20+
# for hydra
21+
if [ "$ARGPARSE" == "hydra" ]; then
22+
ls ./dist-tests/$TEMP-all-hydra/main.py
23+
fi
24+
2025
# Comment dist-tests in .gitignore to make black running on ./dist-tests folder
2126
sed -i "s/dist-tests/# dist-tests/g" .gitignore
2227

scripts/run_tests.sh

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,46 @@ run_spawn_fire() {
9292
done
9393
}
9494

95+
# Hydra test functions
96+
97+
run_simple_hydra() {
98+
for dir in $(find ./dist-tests/$1-simple-hydra -type d)
99+
do
100+
cd $dir
101+
python main.py --config-dir=../../src/tests/ci-configs --config-name=$1-simple.yaml
102+
cd $CWD
103+
done
104+
}
105+
106+
run_all_hydra() {
107+
for dir in $(find ./dist-tests/$1-all-hydra -type d)
108+
do
109+
cd $dir
110+
pytest -vra --color=yes --tb=short test_*.py
111+
python main.py --config-dir=../../src/tests/ci-configs --config-name=$1-all.yaml
112+
cd $CWD
113+
done
114+
}
115+
116+
run_launch_hydra() {
117+
for dir in $(find ./dist-tests/$1-launch-hydra -type d)
118+
do
119+
cd $dir
120+
torchrun --nproc_per_node 2 main.py --config-dir=../../src/tests/ci-configs --config-name=$1-launch.yaml ++backend='gloo'
121+
cd $CWD
122+
done
123+
}
124+
125+
run_spawn_hydra() {
126+
for dir in $(find ./dist-tests/$1-spawn-hydra -type d)
127+
do
128+
cd $dir
129+
python main.py --config-dir=../../src/tests/ci-configs --config-name=$1-spawn.yaml ++backend='gloo'
130+
cd $CWD
131+
done
132+
}
133+
134+
95135

96136
if [ $1 = "unzip" ]; then
97137
unzip_all
@@ -100,23 +140,31 @@ elif [ $1 = "simple" ]; then
100140
run_simple $2
101141
elif [ $3 = "fire" ]; then
102142
run_simple_fire $2
103-
fi
143+
elif [ $3 = "hydra" ]; then
144+
run_simple_hydra $2
145+
fi
104146
elif [ $1 = "all" ]; then
105147
if [ $3 = "argparse" ]; then
106148
run_all $2
107149
elif [ $3 = "fire" ]; then
108150
run_all_fire $2
151+
elif [ $3 = "hydra" ]; then
152+
run_all_hydra $2
109153
fi
110154
elif [ $1 = "launch" ]; then
111155
if [ $3 = "argparse" ]; then
112156
run_launch $2
113157
elif [ $3 = "fire" ]; then
114158
run_launch_fire $2
159+
elif [ $3 = "hydra" ]; then
160+
run_launch_hydra $2
115161
fi
116162
elif [ $1 = "spawn" ]; then
117163
if [ $3 = "argparse" ]; then
118164
run_spawn $2
119165
elif [ $3 = "fire" ]; then
120166
run_spawn_fire $2
167+
elif [ $3 = "hydra" ]; then
168+
run_spawn_hydra $2
121169
fi
122170
fi

src/components/NavColab.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export default {
9393
body: JSON.stringify({
9494
code: store.code,
9595
template: store.config.template,
96-
config: store.config
96+
config: store.config,
97+
argparser: store.config.argparser
9798
})
9899
})
99100
// response body is plain text

0 commit comments

Comments
 (0)