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

[Major] Speedup dataset get_item #1636

Merged
merged 24 commits into from
Sep 3, 2024
Merged

[Major] Speedup dataset get_item #1636

merged 24 commits into from
Sep 3, 2024

Conversation

MaiBe-ctrl
Copy link
Collaborator

No description provided.

Copy link

github-actions bot commented Aug 24, 2024

Model Benchmark

Benchmark Metric main current diff
YosemiteTemps MAE_val 0.57299 0.57299 0.0%
YosemiteTemps RMSE_val 0.84755 0.84755 0.0%
YosemiteTemps Loss_val 0.00042 0.00042 0.0%
YosemiteTemps MAE 0.93964 0.93964 0.0%
YosemiteTemps RMSE 1.65623 1.65623 0.0%
YosemiteTemps Loss 0.00118 0.00118 -0.0%
YosemiteTemps LR 0.0001 0.0001 0.0%
YosemiteTemps time 148.134 59.45 -59.87% 🎉
EnergyPriceDaily MAE_val 5.4019 5.4019 0.0%
EnergyPriceDaily RMSE_val 6.70638 6.70638 -0.0%
EnergyPriceDaily Loss_val 0.02518 0.02518 0.0%
EnergyPriceDaily MAE 5.91313 5.91313 0.0%
EnergyPriceDaily RMSE 7.94013 7.94013 0.0%
EnergyPriceDaily Loss 0.02554 0.02554 0.0%
EnergyPriceDaily LR 0.00029 0.00029 0.0%
EnergyPriceDaily time 39.613 19.81 -49.99% 🎉
AirPassengers MAE_val 30.1289 30.1289 -0.0%
AirPassengers RMSE_val 31.082 31.0819 -0.0%
AirPassengers Loss_val 0.01242 0.01242 -0.0%
AirPassengers MAE 6.12209 6.12209 0.0%
AirPassengers RMSE 7.80953 7.80953 0.0%
AirPassengers Loss 0.00064 0.00064 0.0%
AirPassengers LR 0.0004 0.0004 0.0%
AirPassengers time 9.16971 8.38 -8.61% 🎉
PeytonManning MAE_val 0.35028 0.35028 0.0%
PeytonManning RMSE_val 0.50092 0.50092 0.0%
PeytonManning Loss_val 0.01774 0.01774 0.0%
PeytonManning MAE 0.34667 0.34667 0.0%
PeytonManning RMSE 0.49358 0.49358 -0.0%
PeytonManning Loss 0.01466 0.01466 0.0%
PeytonManning LR 0.00032 0.00032 0.0%
PeytonManning time 25.532 14.91 -41.6% 🎉
Model training plots

Model Training

PeytonManning

YosemiteTemps

AirPassengers

EnergyPriceDaily

@ourownstory
Copy link
Owner

@MaiBe-ctrl Looking great! 2x Speedup!!

Copy link
Owner

@ourownstory ourownstory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! I did a detailed review and noted things that you can make more consistent and raised a few questions. Thank you!

# config_train=self.config_train, # no longer needed since JIT tabularization.
)
loader = DataLoader(dataset, batch_size=min(4096, len(df)), shuffle=False, drop_last=False)
predicted = {}
for name in self.config_seasonality.periods:
predicted[name] = list()
for inputs, _, meta in loader:
for inputs_tensor, meta in loader:
inputs = unpack_sliced_tensor(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this not needed for the other predict_xyz_components methods?

"; ".join(["{}: {}".format(inp, values.shape) for inp, values in inputs.items()])
)
)
input, meta = dataset.__getitem__(0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have one test that tests the unpacking of the tensor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the unpacking logic will be removed inside of the forward call and should be done incrementally when needed instead.

@@ -987,3 +987,153 @@ def configure_trainer(
# config["replace_sampler_ddp"] = False

return pl.Trainer(**config), checkpoint_callback


def unpack_sliced_tensor(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have this function in the same file as stack_all_features

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add a docstring to this function and mention that the returned tensors may not be contiguous.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function will be completely removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we need anyways to make the tensors of the targets contiguous anyways, because doing it like this didn't really solve the problem.

@@ -774,7 +775,17 @@ def loss_func(self, inputs, predicted, targets):
return loss, reg_loss

def training_step(self, batch, batch_idx):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might there be a "create_batch" function called before, where we could place the unpack_sliced_tensor?

Or should we just move the unpacking of each component to each of the components' respective forward call?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we can do this in a subsequent PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the unpacking will be done incrementally in the forward pass.

@@ -51,6 +52,7 @@ def __init__(
config_regressors: Optional[configure.ConfigFutureRegressors] = None,
config_events: Optional[configure.ConfigEvents] = None,
config_holidays: Optional[configure.ConfigCountryHolidays] = None,
config_model: Optional[configure.ConfigModel] = None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this optional?


else:
start_idx, end_idx = feature_indices["time"]
inputs["time"] = sliced_tensor[:, start_idx : end_idx + 1]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include the end_idx here, unlike when max_lags>0?


if "targets" in feature_indices:
targets_start_idx, targets_end_idx = feature_indices["targets"]
inputs["targets"] = sliced_tensor[:, targets_start_idx : targets_end_idx + 1].unsqueeze(1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include the end_idx here, unlike when max_lags>0?

lagged_regressor_start_idx,
]

else:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining dimensions and why most have a unsqueeze(1) added.

# Unpack multiplicative event and holiday features
if "multiplicative_events" in feature_indices:
events_start_idx, events_end_idx = feature_indices["multiplicative_events"]
if "events" not in inputs:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add check also for additive

# Unpack multiplicative regressor features
if "multiplicative_regressors" in feature_indices:
regressors_start_idx, regressors_end_idx = feature_indices["multiplicative_regressors"]
if "regressors" not in inputs:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add check also for additive

# Unpack and process seasonalities
seasonalities_input = None
if self.config_seasonality and self.config_seasonality.periods:
print("++++seasonalities ++++")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print statement from debugging

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still working on cleaning the code 🙈. Let you know once it's ready for review!

max_lags=0,
n_forecasts=1,
config_seasonality=self.config_seasonality,
lagged_regressor_config=self.config_lagged_regressors,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should set elf.config_lagged_regressors to none

@@ -142,11 +147,16 @@ def __init__(
# General
self.config_model = config_model
self.n_forecasts = n_forecasts
self.train_components_stacker = train_components_stacker
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store as dict

@@ -310,6 +320,16 @@ def ar_weights(self) -> torch.Tensor:
if isinstance(layer, nn.Linear):
return layer.weight

def set_components_stacker(self, components_stacker, mode):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store/call as dict

def forward(
self,
input_tensor: torch.Tensor,
components_stacker=ComponentStacker,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

components stacker should not be passed to forward, but rather inferred from a mode-flag

@ourownstory ourownstory merged commit 9c4963c into main Sep 3, 2024
10 of 11 checks passed
@ourownstory ourownstory deleted the speedup_dataset_next branch September 3, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants