Skip to content

Commit

Permalink
Merge pull request #535 from AIStream-Peelout/transformer_timeout2
Browse files Browse the repository at this point in the history
Fix version errors final
  • Loading branch information
isaacmg authored May 10, 2022
2 parents f46171f + 8594e7b commit 0364d93
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 74 deletions.
101 changes: 70 additions & 31 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ orbs:
executors:
python-executor:
docker:
- image: circleci/python:3.9.1
- image: cimg/python:3.10.3
working_directory: ~/repo


Expand Down Expand Up @@ -35,8 +35,9 @@ jobs:
- run:
name: install dependencies
command: |
sudo pip install flake8
flake8 .
python --version
pip install flake8
python -m flake8 .
evaluator_test:
<<: *defaults
Expand All @@ -50,10 +51,10 @@ jobs:
- run:
name: install dependencies
command: |
sudo pip install pipenv
sudo pip install coverage
sudo pip install --quiet --force-reinstall --upgrade -r requirements.txt
sudo python setup.py develop --no-deps
pip install pipenv
pip install coverage
pip install --quiet --force-reinstall --upgrade -r requirements.txt
python setup.py develop --no-deps
- save_cache:
key: requirements-v2-{{ .Branch }}-{{ checksum "requirements.txt" }}
Expand Down Expand Up @@ -93,10 +94,10 @@ jobs:
- run:
name: install dependencies
command: |
sudo pip install pipenv
sudo pip install coverage
sudo pip install --force-reinstall --upgrade -r requirements.txt
sudo python setup.py develop --no-deps
pip install pipenv
pip install coverage
pip install --force-reinstall --upgrade -r requirements.txt
python setup.py develop --no-deps
- save_cache:
key: requirements-v2-{{ .Branch }}-{{ checksum "requirements.txt" }}
Expand Down Expand Up @@ -139,10 +140,10 @@ jobs:
- run:
name: install dependencies
command: |
sudo pip install pipenv
sudo pip install coverage
sudo pip install --force-reinstall --upgrade --quiet -r requirements.txt
sudo python setup.py develop --no-deps
pip install pipenv
pip install coverage
pip install --force-reinstall --upgrade --quiet -r requirements.txt
python setup.py develop --no-deps
- save_cache:
key: requirements-v2-{{ .Branch }}-{{ checksum "requirements.txt" }}
Expand All @@ -163,8 +164,6 @@ jobs:
bash <(curl -s https://codecov.io/bash) -cF python
coverage run -m unittest -v tests/time_model_test.py
bash <(curl -s https://codecov.io/bash) -cF python
coverage run -m unittest -v tests/model_config_tests.py
bash <(curl -s https://codecov.io/bash) -cF python
coverage run -m unittest -v tests/data_loader_tests.py
bash <(curl -s https://codecov.io/bash) -cF python
coverage run -m unittest -v tests/test_da_rnn.py
Expand Down Expand Up @@ -200,10 +199,10 @@ jobs:
- run:
name: install dependencies
command: |
sudo pip install pipenv
sudo pip install coverage
sudo pip install --upgrade --force-reinstall --quiet -r requirements.txt
sudo python setup.py develop --no-deps
pip install pipenv
pip install coverage
pip install --upgrade --force-reinstall --quiet -r requirements.txt
python setup.py develop --no-deps
- save_cache:
key: requirements-v2-{{ .Branch }}-{{ checksum "requirements.txt" }}
Expand Down Expand Up @@ -239,10 +238,10 @@ jobs:
- run:
name: install dependencies
command: |
sudo pip install pipenv
sudo pip install --force-reinstall --upgrade --quiet -r requirements.txt
sudo pip install coverage
sudo python setup.py develop --no-deps
pip install pipenv
pip install --force-reinstall --upgrade --quiet -r requirements.txt
pip install coverage
python setup.py develop --no-deps
- save_cache:
key: requirements-v2-{{ .Branch }}-{{ checksum "requirements.txt" }}
paths:
Expand Down Expand Up @@ -285,7 +284,44 @@ jobs:
coverage run flood_forecast/trainer.py -p tests/full_transformer.json
echo -e 'running trainer_decoder_test \n'
coverage run flood_forecast/trainer.py -p tests/decoder_test.json
echo -e 'running trainer_custom_encode \n'
- store_test_results:
path: test-results

- store_artifacts:
path: test-results
destination: test-results-trainer

- run:
name: upload results
when: always
command: bash <(curl -s https://codecov.io/bash) -cF python


trainer_test1:
<<: *defaults
steps:
- attach_workspace:
at: ~/repo
- restore_cache: # ensure this step occurs *before* installing dependencies
key: requirements-v2-{{ .Branch }}-{{ checksum "requirements.txt" }}

- run:
name: install dependencies
command: |
pip install pipenv
pip install --force-reinstall --upgrade --quiet -r requirements.txt
pip install coverage
python setup.py develop --no-deps
- save_cache:
key: requirements-v2-{{ .Branch }}-{{ checksum "requirements.txt" }}
paths:
- ~/.local

- run:
name: Trainer1 tests
when: always
command: |
coverage run flood_forecast/trainer.py -p tests/custom_encode.json
coverage run flood_forecast/trainer.py -p tests/multi_decoder_test.json
coverage run flood_forecast/trainer.py -p tests/test_dual.json
Expand All @@ -295,7 +331,7 @@ jobs:

- store_artifacts:
path: test-results
destination: test-results-trainer
destination: test-results-trainer2

- run:
name: upload results
Expand All @@ -313,10 +349,10 @@ jobs:
- run:
name: install dependencies
command: |
sudo pip install pipenv
sudo pip install coverage
sudo pip install --upgrade --force-reinstall --quiet -r requirements.txt
sudo python setup.py develop --no-deps
pip install pipenv
pip install coverage
pip install --upgrade --force-reinstall --quiet -r requirements.txt
python setup.py develop --no-deps
- save_cache:
key: requirements-v2-{{ .Branch }}-{{ checksum "requirements.txt" }}
Expand Down Expand Up @@ -370,3 +406,6 @@ workflows:
- plot_test:
requires:
- linting
- trainer_test1:
requires:
- linting
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
max_line_length=120
ignore=E305,W504, E126
max_line_length=121
ignore=E305,W504,E126
max-complexity=18
2 changes: 1 addition & 1 deletion docs/source/buil_dataset.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Build Dataset
Build FF original Dataset
=========================


Expand Down
6 changes: 4 additions & 2 deletions flood_forecast/deployment/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ def infer_now(self, some_date: datetime, csv_path=None, save_buck=None, save_nam
self.inference_params["test_csv_path"] = csv_path
self.inference_params["dataset_params"]["file_path"] = csv_path
df, tensor, history, forecast_start, test, samples = infer_on_torch_model(self.model, **self.inference_params)
print("the tensor shape is 2 ")
print(tensor.shape)
if test.scale and self.n_targets:
unscaled = test.inverse_scale(tensor.numpy())
for i in range(0, self.n_targets):
unscaled = test.inverse_scale(tensor.numpy())
df["pred_" + self.targ_cols[i]] = 0
print("Shape of unscaled is: ")
print(unscaled.shape)
df["pred_" + self.targ_cols[i]][forecast_history:] = unscaled[0, :, i].numpy()
df["pred_" + self.targ_cols[i]][forecast_history:] = unscaled[:, i].numpy()
elif test.scale:
unscaled = test.inverse_scale(tensor.numpy().reshape(-1, 1))
df["preds"][forecast_history:] = unscaled.numpy()[:, 0]
Expand Down
6 changes: 6 additions & 0 deletions flood_forecast/preprocessing/pytorch_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,18 @@ def inverse_scale(
if len(result_data.shape) > 2:
result_data = result_data.permute(2, 0, 1).reshape(result_data.shape[2], -1)
result_data = result_data.permute(1, 0)
elif len(result_data.shape) > 1:
result_data = result_data
else:
result_data = result_data.unsqueeze(0)
result_data_np = result_data.numpy()
if isinstance(result_data, np.ndarray):
result_data_np = result_data
# print(type(result_data))
if self.no_scale:
return torch.from_numpy(result_data_np)
if len(result_data_np.shape) > 2:
result_data_np = result_data_np[0, :, :]
return torch.from_numpy(
self.targ_scaler.inverse_transform(result_data_np)
)
Expand Down
1 change: 1 addition & 0 deletions flood_forecast/time_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def upload_gcs(self, save_path: str, name: str, file_type: str, epoch=0, bucket_
def wandb_init(self):
if self.params["wandb"]:
wandb.init(
id=wandb.util.generate_id(),
project=self.params["wandb"].get("project"),
config=self.params,
name=self.params["wandb"].get("name"),
Expand Down
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
shap==0.40.0
scikit-learn==0.24.2
scikit-learn>=1.0.1
pandas
torch
tb-nightly
seaborn
future
h5py
wandb==0.12.15
wandb==0.12.16
google-cloud
google-cloud-storage
plotly~=5.6.0
pytz~=2022.1
pytz>=2022.1
setuptools~=62.0.0
numpy>=1.21
requests
torchvision>=0.6.0
mpld3~=0.5
mpld3>=0.5
numba>=0.50
sphinx
sphinx-rtd-theme
sphinx-autodoc-typehints
sphinx
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name='flood_forecast',
version='0.995dev',
version='0.9956dev',
packages=[
'flood_forecast',
'flood_forecast.transformer_xl',
Expand Down
2 changes: 1 addition & 1 deletion tests/custom_encode.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test_path": "tests/test_data/keag_small.csv",
"forecast_history":5,
"forecast_length":1,
"train_end": 100,
"train_end": 99,
"valid_start":301,
"valid_end": 401,
"test_start":125,
Expand Down
2 changes: 1 addition & 1 deletion tests/data_loader_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class DataLoaderTests(unittest.TestCase):
"""
Class to test data loader functionality for the code.
Class to test data loader functionality for the code mod.
Specifically, reuturn types and indexing to make sure there is no overlap.
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/decoder_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"training_path": "tests/test_data/keag_small.csv",
"validation_path": "tests/test_data/keag_small.csv",
"test_path": "tests/test_data/keag_small.csv",
"batch_size":4,
"batch_size":10,
"forecast_history":5,
"forecast_length":1,
"train_end": 100,
Expand Down
2 changes: 1 addition & 1 deletion tests/dsanet.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"training_path": "tests/test_data/keag_small.csv",
"validation_path": "tests/test_data/keag_small.csv",
"test_path": "tests/test_data/keag_small.csv",
"batch_size":4,
"batch_size":10,
"forecast_history":10,
"forecast_length":1,
"train_start": 1,
Expand Down
17 changes: 0 additions & 17 deletions tests/model_config_tests.py

This file was deleted.

6 changes: 4 additions & 2 deletions tests/pytorc_train_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,11 @@ def test_handle_meta2(self):
def test_scaling_data(self):
scaled_src, _ = self.model.test_data[0]
data_unscaled = self.model.test_data.original_df.iloc[0:20]["cfs"].values
print("shape bw")
print(scaled_src[:, 0].shape)
inverse_scale = self.model.test_data.inverse_scale(scaled_src[:, 0])
self.assertAlmostEqual(inverse_scale.numpy()[0], data_unscaled[0])
self.assertAlmostEqual(inverse_scale.numpy()[9], data_unscaled[9])
self.assertAlmostEqual(inverse_scale.numpy()[0, 0], data_unscaled[0])
self.assertAlmostEqual(inverse_scale.numpy()[0, 9], data_unscaled[9])

def test_compute_loss_no_scaling(self):
exam = torch.Tensor([4.0]).repeat(2, 20, 5)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_explain_model_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ModelInterpretabilityTest(unittest.TestCase):
"project": "repo-flood_forecast",
},
"inference_params": {
"hours_to_forecast": 30,
"hours_to_forecast": 32,
"datetime_start": datetime(2014, 6, 2, 0),
},
}
Expand All @@ -54,7 +54,7 @@ class ModelInterpretabilityTest(unittest.TestCase):
"project": "repo-flood_forecast",
},
"inference_params": {
"hours_to_forecast": 30,
"hours_to_forecast": 32,
"datetime_start": datetime(2014, 6, 2, 0),
},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_inf_single.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

},
"lr": 0.4,
"epochs": 3,
"epochs": 1,
"batch_size":4

},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_informer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"lr": 0.04
},

"epochs": 6,
"epochs": 1,
"batch_size":5

},
Expand Down
Loading

0 comments on commit 0364d93

Please sign in to comment.