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

move tensor to cpu before numpy #1949

Merged
merged 2 commits into from
Aug 11, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ but cannot always guarantee backwards compatibility. Changes that may **break co

**Fixed**
- Fixed a bug in `TimeSeries.from_dataframe()` when using a pandas.DataFrame with `df.columns.name != None`. [#1938](https://github.com/unit8co/darts/pull/1938) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug when using `TFTExplainer` with a `TFTModel` running on GPU. [#1949](https://github.com/unit8co/darts/pull/1949) by [Dennis Bader](https://github.com/dennisbader).


## [0.25.0](https://github.com/unit8co/darts/tree/0.25.0) (2023-08-04)
Expand Down
5 changes: 3 additions & 2 deletions darts/explainability/tft_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def explain(
# get the weights and the attention head from the trained model for the prediction
# aggregate over attention heads
attention_heads = (
self.model.model._attn_out_weights.detach().numpy().sum(axis=-2)
self.model.model._attn_out_weights.detach().cpu().numpy().sum(axis=-2)
)
# get the variable importances (pd.DataFrame with rows corresponding to the number of input series)
encoder_importance = self._encoder_importance
Expand Down Expand Up @@ -501,7 +501,8 @@ def _get_importance(

# transform the encoder/decoder weights to percentages, rounded to n_decimals
weights_percentage = (
weight.detach().numpy().mean(axis=1).squeeze(axis=1).round(n_decimals) * 100
weight.detach().cpu().numpy().mean(axis=1).squeeze(axis=1).round(n_decimals)
* 100
)
# create a dataframe with the variable names and the weights
name_mapping = self._name_mapping
Expand Down