Skip to content

Commit 59b0a1d

Browse files
committed
Merge branch 'develop' of https://github.com/ECP-Candle/Benchmarks into develop
2 parents f5ece95 + a9b7906 commit 59b0a1d

File tree

6 files changed

+47
-55
lines changed

6 files changed

+47
-55
lines changed

Pilot1/Uno/test.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
set -x
44

55
# AUC prediction model
6-
if [ ! -f "top_21_auc_1fold.uno.h5" ]; then
7-
curl -o top_21_auc_1fold.uno.h5 http://ftp.mcs.anl.gov/pub/candle/public/benchmarks/Pilot1/uno/top_21_auc_1fold.uno.h5
6+
if [ ! -f "$CANDLE_DATA_DIR/Pilot1/Uno/top_21_auc_1fold.uno.h5" ]; then
7+
# download from http://ftp.mcs.anl.gov/pub/candle/public/benchmarks/Pilot1/uno/top_21_auc_1fold.uno.h5
8+
python -c 'from candle import get_file;get_file(fname="top_21_auc_1fold.uno.h5", origin="https://ftp.mcs.anl.gov/pub/candle/public/benchmarks/Pilot1/uno/top_21_auc_1fold.uno.h5", cache_subdir="Pilot1/Uno")'
89
fi
910

10-
python uno_baseline_keras2.py --config_file uno_auc_model.txt --use_exported_data top_21_auc_1fold.uno.h5 -e 3 --save_weights save/saved.model.weights.h5
11-
python uno_infer.py --data top_21_auc_1fold.uno.h5 \
11+
python uno_baseline_keras2.py --config_file uno_auc_model.txt --use_exported_data "$CANDLE_DATA_DIR/Pilot1/Uno/top_21_auc_1fold.uno.h5" -e 3 --save_weights save/saved.model.weights.h5
12+
python uno_infer.py --data "$CANDLE_DATA_DIR/Pilot1/Uno/top_21_auc_1fold.uno.h5" \
1213
--model_file save/'uno.A=relu.B=32.E=3.O=adamax.LR=0.0001.CF=r.DF=d.DR=0.1.wu_lr.re_lr.L1000.D1=1000.D2=1000.D3=1000.D4=1000.D5=1000.FD1=1000.FD2=1000.FD3=1000.FD4=1000.FD5=1000.model.json' \
1314
--weights_file save/saved.model.weights.h5 \
1415
--partition val \
@@ -17,5 +18,5 @@ python uno_infer.py --data top_21_auc_1fold.uno.h5 \
1718
--agg_dose AUC
1819

1920
# CLR model
20-
python uno_clr_keras2.py --config_file uno_auc_clr_model.txt --use_exported_data top_21_auc_1fold.uno.h5 -e 3
21+
python uno_clr_keras2.py --config_file uno_auc_clr_model.txt --use_exported_data ../../Data/Pilot1/Uno/top_21_auc_1fold.uno.h5 -e 3
2122

Pilot3/P3B7/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def _download(self):
200200
self._preprocess(raw_data)
201201

202202
def _preprocess(self, raw_data):
203-
print(f"Preprocessing data...")
203+
print(f'{"Preprocessing data..."}')
204204
self._make_processed_dirs()
205205

206206
with open(raw_data, 'rb') as f:
@@ -215,7 +215,7 @@ def _preprocess(self, raw_data):
215215
self._save_split('train', corpus.train, y_train)
216216
self._save_split('valid', corpus.valid, y_valid)
217217
self._save_vocab(corpus.vocab)
218-
print(f"Done!")
218+
print(f'{"Done!"}')
219219

220220
def _save_split(self, split, data, target):
221221
target = self._create_target(target)

Pilot3/P3B7/p3b7_baseline_pytorch.py

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import p3b7 as bmk
33
import candle
44

5-
import numpy as np
5+
import pandas as pd
6+
from pathlib import Path
67

7-
import torch.nn as nn
88
from torch.utils.data import DataLoader
99

1010
from data import P3B3, Egress
@@ -13,10 +13,7 @@
1313
from meters import AccuracyMeter
1414
from metrics import F1Meter
1515

16-
from prune import (
17-
negative_prune, min_max_prune,
18-
create_prune_masks, remove_prune_masks
19-
)
16+
from prune import create_prune_masks, remove_prune_masks
2017

2118

2219
TASKS = {
@@ -134,47 +131,35 @@ def evaluate(model, loader, device):
134131

135132
accmeter.update_accuracy()
136133

137-
print(f'Validation accuracy:')
134+
print(f'{"Validation accuracy:"}')
138135
accmeter.print_task_accuracies()
139136

140137
loss /= len(loader.dataset)
141138

142139
return loss
143140

144141

145-
def save_dataframe(metrics, filename):
142+
def save_dataframe(metrics, filename, args):
146143
"""Save F1 metrics"""
147144
df = pd.DataFrame(metrics, index=[0])
148-
path = Path(ARGS.savepath).joinpath(f'f1/{filename}.csv')
145+
path = Path(args.savepath).joinpath(f'f1/{filename}.csv')
149146
df.to_csv(path, index=False)
150147

151148

152149
def run(args):
153150
args = candle.ArgumentStruct(**args)
154151
args.cuda = torch.cuda.is_available()
155-
args.device = torch.device(f"cuda" if args.cuda else "cpu")
156-
157-
if args.use_synthetic_data:
158-
train_data, valid_data = get_synthetic_data(args)
159-
160-
hparams = Hparams(
161-
kernel1=args.kernel1,
162-
kernel2=args.kernel2,
163-
kernel3=args.kernel3,
164-
embed_dim=args.embed_dim,
165-
n_filters=args.n_filters,
166-
)
167-
else:
168-
train_data, valid_data = get_egress_data(tasks)
169-
170-
hparams = Hparams(
171-
kernel1=args.kernel1,
172-
kernel2=args.kernel2,
173-
kernel3=args.kernel3,
174-
embed_dim=args.embed_dim,
175-
n_filters=args.n_filters,
176-
vocab_size=len(train_data.vocab)
177-
)
152+
args.device = torch.device(f'{"cuda"}' if args.cuda else "cpu")
153+
154+
train_data, valid_data = get_synthetic_data(args)
155+
156+
hparams = Hparams(
157+
kernel1=args.kernel1,
158+
kernel2=args.kernel2,
159+
kernel3=args.kernel3,
160+
embed_dim=args.embed_dim,
161+
n_filters=args.n_filters,
162+
)
178163

179164
train_loader = DataLoader(train_data, batch_size=args.batch_size)
180165
valid_loader = DataLoader(valid_data, batch_size=args.batch_size)

Pilot3/P3B7/prune.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ def compute_mask(self, t, default_mask):
128128
# Check that the amount of units to prune is not > than the number of
129129
# parameters in t
130130
tensor_size = t.nelement()
131-
tNP = t.detach().cpu().numpy()
132131
# Compute number of units to prune: amount if int,
133132
# else amount * tensor_size
134133
nparams_toprune = _compute_nparams_toprune(self.amount, tensor_size)

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ At this point, we will refer to a benchmark by it's problem area and benchmark n
1717

1818
Over time, we will be adding implementations that make use of different tensor frameworks. The primary (baseline) benchmarks are implemented using keras, and are named with '_baseline' in the name, for example p3b1_baseline_keras2.py.
1919

20-
Implementations that use alternative tensor frameworks, such as mxnet or neon, will have the name of the framework in the name. Examples can be seen in the P1B3 benchmark contribs/ directory, for example:
21-
p1b3_mxnet.py
22-
p1b3_neon.py
20+
Implementations that use alternative tensor frameworks, such as pytorch, will have the name of the framework in the name. Examples can be seen in the Pilot1 benchmark UnoMT directory, for example: `unoMT_baseline_pytorch.py`
2321

24-
Documentation: https://ecp-candle.github.io/Candle/html/readme.html
22+
Documentation: https://ecp-candle.github.io/Candle/

common/uq_keras_utils.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -759,15 +759,15 @@ def loss(y_true, y_pred):
759759

760760
y_shape = K.shape(y_true)
761761
if nout > 1:
762-
y_out0 = K.reshape(y_pred[:, 0::nout], y_shape)
763-
y_out1 = K.reshape(y_pred[:, 1::nout], y_shape)
764-
y_out2 = K.reshape(y_pred[:, 2::nout], y_shape)
762+
y_qtl0 = K.reshape(y_pred[:, 0::3], y_shape)
763+
y_qtl1 = K.reshape(y_pred[:, 1::3], y_shape)
764+
y_qtl2 = K.reshape(y_pred[:, 2::3], y_shape)
765765
else:
766-
y_out0 = K.reshape(y_pred[:, 0], y_shape)
767-
y_out1 = K.reshape(y_pred[:, 1], y_shape)
768-
y_out2 = K.reshape(y_pred[:, 2], y_shape)
766+
y_qtl0 = K.reshape(y_pred[:, 0], y_shape)
767+
y_qtl1 = K.reshape(y_pred[:, 1], y_shape)
768+
y_qtl2 = K.reshape(y_pred[:, 2], y_shape)
769769

770-
return quantile_loss(lowquantile, y_true, y_out1) + quantile_loss(highquantile, y_true, y_out2) + 2. * quantile_loss(0.5, y_true, y_out0)
770+
return quantile_loss(lowquantile, y_true, y_qtl1) + quantile_loss(highquantile, y_true, y_qtl2) + 2. * quantile_loss(0.5, y_true, y_qtl0)
771771

772772
return loss
773773

@@ -795,10 +795,10 @@ def metric(y_true, y_pred):
795795
"""
796796
y_shape = K.shape(y_true)
797797
if nout > 1:
798-
y_out = K.reshape(y_pred[:, index::nout], y_shape)
798+
y_qtl = K.reshape(y_pred[:, index::3], y_shape)
799799
else:
800-
y_out = K.reshape(y_pred[:, index], y_shape)
801-
return quantile_loss(quantile, y_true, y_out)
800+
y_qtl = K.reshape(y_pred[:, index], y_shape)
801+
return quantile_loss(quantile, y_true, y_qtl)
802802

803803
metric.__name__ = 'quantile_{}'.format(quantile)
804804
return metric
@@ -819,7 +819,11 @@ def add_index_to_output(y_train):
819819
"""
820820
# Add indices to y
821821
y_train_index = range(y_train.shape[0])
822-
y_train_augmented = np.vstack([y_train, y_train_index]).T
822+
if y_train.ndim > 1:
823+
shp = (y_train.shape[0], 1)
824+
y_train_augmented = np.hstack([y_train, np.reshape(y_train_index, shp)])
825+
else:
826+
y_train_augmented = np.vstack([y_train, y_train_index]).T
823827

824828
return y_train_augmented
825829

@@ -884,6 +888,11 @@ def __init__(self, x, y, a_max=0.99):
884888
Maximum value of a variable to allow
885889
"""
886890
super(Contamination_Callback, self).__init__()
891+
if y.ndim > 1:
892+
if y.shape[1] > 1:
893+
raise Exception(
894+
'ERROR ! Contamination model can be applied to one-output regression, but provided training data has: '
895+
+ str(y.ndim) + 'outpus... Exiting')
887896

888897
self.x = x # Features of training set
889898
self.y = y # Output of training set

0 commit comments

Comments
 (0)