Skip to content

Commit

Permalink
move tensor to cpu before numpy (#1949)
Browse files Browse the repository at this point in the history
* move tensor to cpu before numpy

* update changelog
  • Loading branch information
dennisbader committed Aug 11, 2023
1 parent dbed6be commit cf57f77
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
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

0 comments on commit cf57f77

Please sign in to comment.