Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add profiling using cprofile #644

Draft
wants to merge 6 commits into
base: masterr
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ jobs:
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
coverage run flood_forecast/trainer.py -p tests/dsanet.json
python -m cProfile -s cumulative flood_forecast/trainer.py -p tests/dsanet.json

- store_test_results:
path: test-results
Expand Down
2 changes: 1 addition & 1 deletion flood_forecast/basic/gru_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __init__(self, n_time_series: int, hidden_dim: int, num_layers: int, n_targe

:param n_time_series: The number of time series present in the data
:type n_time_series int:
:param hidden_dim:
:param hidden_dim: The hidden dimension of the GRU
:type hidden_dim:

Note for probablistic n_targets must be set to two and actual multiple targs are not supported now.
Expand Down
2 changes: 1 addition & 1 deletion flood_forecast/preprocessing/closest_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_closest_gage(
start_row: int,
end_row: int):
# Function that calculates the closest weather stations to gage and stores in JSON
# Base u
# Base u r
for row in range(start_row, end_row):
gage_info = {}
gage_info["river_id"] = int(gage_df.iloc[row]['id'])
Expand Down
5 changes: 5 additions & 0 deletions flood_forecast/pytorch_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from flood_forecast.training_utils import EarlyStopper
from flood_forecast.custom.custom_opt import GaussianLoss, MASELoss
from torch.nn import CrossEntropyLoss
import line_profiler

profile = line_profiler.LineProfiler()


def multi_crit(crit_multi: List, output, labels, valid=None):
Expand Down Expand Up @@ -220,6 +223,7 @@ def train_transformer_style(
print("test loss:", test)
model.params["run"] = session_params
model.save_model(model_filepath, max_epochs)
profile.print_stats()


def get_meta_representation(column_id: str, uuid: str, meta_model: PyTorchForecast) -> torch.Tensor:
Expand Down Expand Up @@ -340,6 +344,7 @@ def compute_loss(labels, output, src, criterion, validation_dataset, probabilist
return loss


@profile
def torch_single_train(model: PyTorchForecast,
opt: optim.Optimizer,
criterion: Type[torch.nn.modules.loss._Loss],
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ sphinx
sphinx-rtd-theme
sphinx-autodoc-typehints
sphinx
line_profiler
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='1.0000dev',
version='1.0dev',
packages=[
'flood_forecast',
'flood_forecast.transformer_xl',
Expand Down