Skip to content

Commit 787431d

Browse files
author
Suman Michael
committed
changes from ada
1 parent 519c03b commit 787431d

9 files changed

Lines changed: 117 additions & 15 deletions

File tree

conf/config.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defaults:
22
- trainer: default
3-
- data: default
3+
- data: ada
44
- model: default
55
- optim: default
66
- logger: default
@@ -10,4 +10,15 @@ defaults:
1010

1111
hydra:
1212
run:
13-
dir: .
13+
dir: .
14+
15+
trainer:
16+
gpus: 1
17+
profiler: null
18+
progress_bar_refresh_rate: 10
19+
benchmark: true
20+
21+
data:
22+
batch_size: 32
23+
num_workers: 1
24+
random_sampler: false

conf/data/ada.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defaults:
2+
- default
3+
4+
train_list: /ssd_scratch/cvit/sumanmichael/annotation_txt_files/c1_10l.txt
5+
val_list: /ssd_scratch/cvit/sumanmichael/annotation_txt_files/val.txt

conf/optim/default.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
lr: 1.0
2+
rho: 0.9
23
eps: 1.0e-06
34
weight_decay: 0

conf/trainer/default.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ weights_save_path: null
3939
num_sanity_val_steps: 2
4040
truncated_bptt_steps: null
4141
resume_from_checkpoint: null
42-
profiler: pytorch
42+
profiler: null
4343
benchmark: false
4444
deterministic: false
4545
reload_dataloaders_every_n_epochs: 0
@@ -55,4 +55,4 @@ amp_level: O2
5555
distributed_backend: null
5656
move_metrics_to_cpu: false
5757
multiple_trainloader_mode: max_size_cycle
58-
stochastic_weight_avg: false
58+
stochastic_weight_avg: false

run.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
#SBATCH --time=6-00:00:00
3+
#SBATCH -A sumanmichael
4+
#SBATCH --partition=long
5+
#SBATCH --gres=gpu:2
6+
#SBATCH --mem-per-cpu=2G
7+
#SBATCH -c 20
8+
#SBATCH --mail-user=sumanmichael01@gmail.com
9+
#SBATCH --mail-type=ALL
10+
11+
echo "Running on $(hostname)"
12+
13+
#echo "Loading Cuda Modules" &&
14+
module load cuda/10.2 &&
15+
module load cudnn/7.6.5-cuda-10.2 &&
16+
#echo "Loaded cuda modules" &&
17+
18+
echo "Starting Data Transfer"
19+
echo "-----------------------------------"
20+
echo "Annotations Transfer:"
21+
rsync -az --info=progress2 sumanmichael@ada.iiit.ac.in:/share3/sumanmichael/annotation_txt_files /ssd_scratch/cvit/sumanmichael/ &&
22+
echo "Images Transfer:"
23+
rsync -az --info=progress2 sumanmichael@ada.iiit.ac.in:/share3/bvk_cvit/img_data /ssd_scratch/cvit/sumanmichael/ &&
24+
echo "Codebase Transfer:"
25+
rm -rf /ssd_scratch/cvit/sumanmichael/seq2seq-attention-ocr-pytorch
26+
rsync -az --info=progress2 sumanmichael@ada.iiit.ac.in:/home2/sumanmichael/seq2seq-attention-ocr-pytorch /ssd_scratch/cvit/sumanmichael/ &&
27+
echo "Data Transfer successful"
28+
29+
echo "-----------------------------------"
30+
31+
source /home2/sumanmichael/miniconda3/etc/profile.d/conda.sh &&
32+
conda activate pl &&
33+
echo "conda env Activated!" &&
34+
35+
cd /ssd_scratch/cvit/sumanmichael/seq2seq-attention-ocr-pytorch &&
36+
echo "-------------------------------"
37+
echo " CUDA VERSIONS "
38+
echo "--------nvidia-smi-------------"
39+
nvidia-smi
40+
echo "--------nvcc-------------------"
41+
nvcc --version
42+
echo "---------pytorch-cuda----------"
43+
python -c "import torch; print('TORCH_CUDA_V:',torch.version.cuda)"
44+
echo "-------------------------------"
45+
46+
CUDA_LAUNCH_BLOCKING=1;HYDRA_FULL_ERROR=1 python train.py logger.name="$1"

run_pt.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
#SBATCH --time=6-00:00:00
3+
#SBATCH -A sumanmichael
4+
#SBATCH --partition=long
5+
#SBATCH --gres=gpu:1
6+
#SBATCH --mem-per-cpu=2G
7+
#SBATCH -c 20
8+
#SBATCH --mail-user=sumanmichael01@gmail.com
9+
#SBATCH --mail-type=ALL
10+
11+
echo "Running on $(hostname)"
12+
13+
#echo "Loading Cuda Modules" &&
14+
module load cuda/10.2 &&
15+
module load cudnn/7.6.5-cuda-10.2 &&
16+
#echo "Loaded cuda modules" &&
17+
18+
echo "Starting Data Transfer"
19+
echo "-----------------------------------"
20+
echo "Annotations Transfer:"
21+
rsync -az --info=progress2 sumanmichael@ada.iiit.ac.in:/share3/sumanmichael/annotation_txt_files /ssd_scratch/cvit/sumanmichael/ &&
22+
echo "Images Transfer:"
23+
rsync -az --info=progress2 sumanmichael@ada.iiit.ac.in:/share3/bvk_cvit/img_data /ssd_scratch/cvit/sumanmichael/ &&
24+
echo "Codebase Transfer:"
25+
rm -rf /ssd_scratch/cvit/sumanmichael/seq2seq-attention-ocr-pytorch
26+
rsync -az --info=progress2 sumanmichael@ada.iiit.ac.in:/home2/sumanmichael/seq2seq-attention-ocr-pytorch /ssd_scratch/cvit/sumanmichael/ &&
27+
echo "Data Transfer successful"
28+
29+
echo "-----------------------------------"
30+
31+
source /home2/sumanmichael/miniconda3/etc/profile.d/conda.sh &&
32+
conda activate pl &&
33+
echo "conda env Activated!" &&
34+
35+
cd /ssd_scratch/cvit/sumanmichael/seq2seq-attention-ocr-pytorch &&
36+
echo "-------------------------------"
37+
echo " CUDA VERSIONS "
38+
echo "--------nvidia-smi-------------"
39+
nvidia-smi
40+
echo "--------nvcc-------------------"
41+
nvcc --version
42+
echo "---------pytorch-cuda----------"
43+
python -c "import torch; print('TORCH_CUDA_V:',torch.version.cuda)"
44+
echo "-------------------------------"
45+
46+
UDA_LAUNCH_BLOCKING=1;HYDRA_FULL_ERROR=1 python train_pt.py --train_list /ssd_scratch/cvit/sumanmichael/annotation_txt_files/c1_10l.txt --eval_list /ssd_scratch/cvit/sumanmichael/annotation_txt_files/val.txt --num_epochs 100 --learning_rate 0.1

src/aocr.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ def training_step(self, train_batch, batch_idx, optimizer_idx=None):
145145
'train/loss': loss,
146146
# 'train_wer': self.wer(decoder_outputs, target_variable) # batch WER?
147147
}
148-
for k, v in log_dict.items():
149-
self.logger.experiment[k].log(v)
150148
self.log_dict(log_dict)
151149
return loss
152150

@@ -165,8 +163,6 @@ def validation_step(self, val_batch, batch_idx, optimizer_idx=None):
165163
'val/wer': self.wer(decoder_outputs, target_variable),
166164
'val/cer': self.cer(decoder_outputs, target_variable)
167165
}
168-
for k,v in log_dict.items():
169-
self.logger.experiment[k].log(v)
170166
self.log_dict(log_dict)
171167
return loss
172168

src/modules/decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def forward(self, prev_output, attention_context, state):
9494
# TODO: COMPLETED
9595
attention_context, attention_weights = self.attention(state_flat)
9696
# moving to cpu to prevent bloating in GPU
97-
self.attention_weights_history.append(attention_weights.detach().to("cpu"))
97+
# self.attention_weights_history.append(attention_weights.detach().to("cpu"))
9898

9999
cell_output = cell_output.permute(1, 0, 2)
100100
out_proj_inp = torch.cat((cell_output, attention_context), dim=2)

train_pt.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from src.utils import utils, dataset
1212
from src.utils.utils import get_alphabet
1313

14+
import dotenv; dotenv.load_dotenv()
1415
import neptune.new as neptune
1516

1617
alphabet = get_alphabet()
@@ -37,7 +38,6 @@ def train(train_loader, encoder, decoder, criterion, logger, teach_forcing_prob=
3738

3839
for epoch in range(cfg.num_epochs):
3940
train_iter = iter(train_loader)
40-
4141
for i in range(len(train_loader)):
4242
cpu_images, cpu_texts = train_iter.next()
4343
batch_size = cpu_images.size(0)
@@ -56,11 +56,8 @@ def train(train_loader, encoder, decoder, criterion, logger, teach_forcing_prob=
5656

5757
target_variable = target_variable.cuda()
5858

59-
decoder_outputs = []
60-
6159
for di in range(1, max_length):
6260
decoder_output, attention_context, state = decoder(decoder_input, attention_context, state)
63-
decoder_outputs.append(decoder_output)
6461
if di == 1:
6562
loss = criterion(decoder_output, target_variable[di])
6663
else:
@@ -69,6 +66,7 @@ def train(train_loader, encoder, decoder, criterion, logger, teach_forcing_prob=
6966
decoder_input = utils.get_one_hot(target_variable[di], num_classes)
7067
else:
7168
_, topi = decoder_output.data.topk(1)
69+
del decoder_output
7270
topi = topi.detach()
7371
ni = topi.T[0]
7472
decoder_input = utils.get_one_hot(ni, num_classes)
@@ -77,8 +75,7 @@ def train(train_loader, encoder, decoder, criterion, logger, teach_forcing_prob=
7775
decoder.zero_grad()
7876
loss.backward()
7977

80-
logger["train/loss"].log(loss)
81-
del loss
78+
logger["train/loss"].log(loss.item())
8279
encoder_optimizer.step()
8380
decoder_optimizer.step()
8481

0 commit comments

Comments
 (0)