Skip to content

Commit

Permalink
Merge pull request #16 from mhpi/highflow-expert
Browse files Browse the repository at this point in the history
high-flow commit 2
  • Loading branch information
taddyb authored Nov 26, 2023
2 parents dca85ca + 6cda808 commit d60208a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: mhpihydrodl
name: hydrodl_new
channels:
- pytorch
- nvidia
Expand Down
8 changes: 4 additions & 4 deletions example/StreamflowExample-DI.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
gpuid = 6
torch.cuda.set_device(gpuid)


# Set hyperparameters
EPOCH = 300
BATCH_SIZE = 100
Expand All @@ -57,6 +56,7 @@
forType = 'daymet'
trainBuff = 365
loadTrain = True
subset_train = 'All' #give the list of basins to train on or else fix 'All' to use all

# Fix random seed
seedid = 111111
Expand Down Expand Up @@ -104,7 +104,7 @@
'geol_2nd_class', 'glim_2nd_class_frac', 'carbonate_rocks_frac', 'geol_porostiy', 'geol_permeability']
optData = default.optDataCamels
optData = default.update(
optData, varT=varF, varC=attrLst, tRange=Ttrain, forType=forType) # Update the training period
optData, varT=varF, varC=attrLst, tRange=Ttrain, forType=forType, subset=subset_train) # Update the training period

# if (interfaceOpt == 1) and (2 not in Action):
if (interfaceOpt == 1) and (loadTrain is True):
Expand Down Expand Up @@ -171,7 +171,7 @@
)

# define output folder for model results
exp_name = f"CAMELSDemo-torch={torch.__version__}"
exp_name = f"CAMELSDemo"
exp_disp = "TestRun"
save_path = os.path.join(
exp_name,
Expand Down Expand Up @@ -199,7 +199,7 @@
ny = yTrain.shape[-1]
# load model for training
if torch.cuda.is_available():
model = CudnnLstmModel(nx=nx, ny=ny, hiddenSize=HIDDENSIZE, warmUpDay=trainBuff)
model = CudnnLstmModel(nx=nx, ny=ny, hiddenSize=HIDDENSIZE)
else:
model = CpuLstmModel(nx=nx, ny=ny, hiddenSize=HIDDENSIZE)
optModel = default.update(optModel, nx=nx, ny=ny)
Expand Down
2 changes: 1 addition & 1 deletion hydroDL/data/camels.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def __init__(self, *, subset="All", tRange, forType='nldas'):
elif type(subset) is list:
self.usgsId = np.array(subset)
crd = np.zeros([len(self.usgsId), 2])
ind = np.full(len(self.usgsId), np.nan).astype(int)
ind = np.full(len(self.usgsId), -1, dtype=int)
for ii in range(len(self.usgsId)):
tempind = np.where(gageDict["id"] == self.usgsId[ii])
ind[ii] = tempind[0][0]
Expand Down
5 changes: 4 additions & 1 deletion hydroDL/model/dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import torch.nn


def createMask(x, dr):

def createMask(x, dr, seed):
generator = torch.Generator(device="cuda")
generator.manual_seed(seed)
mask = x.new().resize_as_(x).bernoulli_(1 - dr).div_(1 - dr).detach_()
# print('droprate='+str(dr))
return mask
Expand Down
7 changes: 4 additions & 3 deletions hydroDL/model/rnn/CudnnLstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class CudnnLstm(nn.Module):
def __init__(self, *, inputSize, hiddenSize, dr=0.5, drMethod="drW", gpu=0):
def __init__(self, *, inputSize, hiddenSize, dr=0.5, drMethod="drW", gpu=0, seed=42):
super(CudnnLstm, self).__init__()
self.inputSize = inputSize
self.hiddenSize = hiddenSize
Expand All @@ -23,6 +23,7 @@ def __init__(self, *, inputSize, hiddenSize, dr=0.5, drMethod="drW", gpu=0):
self._all_weights = [["w_ih", "w_hh", "b_ih", "b_hh"]]
self.cuda()
self.name = "CudnnLstm"
self.seed = seed
self.is_legacy = True

self.reset_mask()
Expand All @@ -42,8 +43,8 @@ def __setstate__(self, d):
self._all_weights = [["w_ih", "w_hh", "b_ih", "b_hh"]]

def reset_mask(self):
self.maskW_ih = createMask(self.w_ih, self.dr)
self.maskW_hh = createMask(self.w_hh, self.dr)
self.maskW_ih = createMask(self.w_ih, self.dr, self.seed)
self.maskW_hh = createMask(self.w_hh, self.dr, self.seed)

def reset_parameters(self):
stdv = 1.0 / math.sqrt(self.hiddenSize)
Expand Down

0 comments on commit d60208a

Please sign in to comment.