From bcd9955adface6e182b30dfa882e0ab9ac3e05be Mon Sep 17 00:00:00 2001 From: DouglasOrr <> Date: Mon, 2 Oct 2023 13:43:55 +0000 Subject: [PATCH] DouglasOrr published a site update --- core.html | 65 +- example.html | 18 +- index.html | 44 +- usage.html | 7677 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 7753 insertions(+), 51 deletions(-) create mode 100644 usage.html diff --git a/core.html b/core.html index f5990b1..7d4ab3d 100644 --- a/core.html +++ b/core.html @@ -27,7 +27,7 @@

Module tensor_tracker.core

as usual. Your Tracker will be filled with a list of Stashes, containing copies of fwd/bwd tensors at (sub)module outputs. (Beware, this can consume a lot of memory.)

-

Usage:

+

Usage (notebook):

with tensor_tracker.track(model) as tracker:
     model(inputs).backward()
 
@@ -56,8 +56,8 @@ 

Module tensor_tracker.core

tracker = Tracker(); tracker.register(...); tracker.unregister()

-

See also: example of -visualising transformer activations & gradients using UMAP.

+

See also: example of +visualising transformer activations & gradients using UMAP.

Expand source code @@ -71,7 +71,7 @@

Module tensor_tracker.core

copies of fwd/bwd tensors at (sub)module outputs. (Beware, this can consume a lot of memory.) -Usage: +Usage ([notebook](usage.html)): ``` with tensor_tracker.track(model) as tracker: @@ -98,8 +98,8 @@

Module tensor_tracker.core

- Manually register/unregister hooks: `tracker = Tracker(); tracker.register(...); tracker.unregister()` -See also: example of -[visualising transformer activations & gradients using UMAP](example.html). +See also: [example of +visualising transformer activations & gradients using UMAP](example.html). """ import dataclasses @@ -278,16 +278,21 @@

Module tensor_tracker.core

return len(self.stashes) def to_frame( - self, stat: Callable[[Tensor], Tensor] = torch.std + self, + stat: Callable[[Tensor], Tensor] = torch.std, + stat_name: Optional[str] = None, ) -> "pandas.DataFrame": # type:ignore[name-defined] # NOQA: F821 import pandas + column_name = ( + getattr(stat, "__name__", "value") if stat_name is None else stat_name + ) + def to_item(stash: Stash) -> Dict[str, Any]: d = stash.__dict__.copy() - first_value = stash.first_value - d["value"] = ( - stat(first_value).item() if isinstance(first_value, Tensor) else None - ) + d.pop("value") + v = stash.first_value + d[column_name] = stat(v).item() if isinstance(v, Tensor) else None d["type"] = f"{stash.type.__module__}.{stash.type.__name__}" return d @@ -407,7 +412,7 @@

Functions

as usual. Your Tracker will be filled with a list of Stashes, containing copies of fwd/bwd tensors at (sub)module outputs. (Beware, this can consume a lot of memory.)

-

Usage:

+

Usage (notebook):

with tensor_tracker.track(model) as tracker:
     model(inputs).backward()
 
@@ -436,8 +441,8 @@ 

Functions

tracker = Tracker(); tracker.register(...); tracker.unregister()

-

See also: example of -visualising transformer activations & gradients using UMAP.

+

See also: example of +visualising transformer activations & gradients using UMAP.

Expand source code @@ -671,16 +676,21 @@

Instance variables

return len(self.stashes) def to_frame( - self, stat: Callable[[Tensor], Tensor] = torch.std + self, + stat: Callable[[Tensor], Tensor] = torch.std, + stat_name: Optional[str] = None, ) -> "pandas.DataFrame": # type:ignore[name-defined] # NOQA: F821 import pandas + column_name = ( + getattr(stat, "__name__", "value") if stat_name is None else stat_name + ) + def to_item(stash: Stash) -> Dict[str, Any]: d = stash.__dict__.copy() - first_value = stash.first_value - d["value"] = ( - stat(first_value).item() if isinstance(first_value, Tensor) else None - ) + d.pop("value") + v = stash.first_value + d[column_name] = stat(v).item() if isinstance(v, Tensor) else None d["type"] = f"{stash.type.__module__}.{stash.type.__name__}" return d @@ -750,7 +760,7 @@

Methods

-def to_frame(self, stat: Callable[[torch.Tensor], torch.Tensor] = <built-in method std of type object>) ‑> pandas.DataFrame +def to_frame(self, stat: Callable[[torch.Tensor], torch.Tensor] = <built-in method std of type object>, stat_name: Optional[str] = None) ‑> pandas.DataFrame
@@ -759,16 +769,21 @@

Methods

Expand source code
def to_frame(
-    self, stat: Callable[[Tensor], Tensor] = torch.std
+    self,
+    stat: Callable[[Tensor], Tensor] = torch.std,
+    stat_name: Optional[str] = None,
 ) -> "pandas.DataFrame":  # type:ignore[name-defined] # NOQA: F821
     import pandas
 
+    column_name = (
+        getattr(stat, "__name__", "value") if stat_name is None else stat_name
+    )
+
     def to_item(stash: Stash) -> Dict[str, Any]:
         d = stash.__dict__.copy()
-        first_value = stash.first_value
-        d["value"] = (
-            stat(first_value).item() if isinstance(first_value, Tensor) else None
-        )
+        d.pop("value")
+        v = stash.first_value
+        d[column_name] = stat(v).item() if isinstance(v, Tensor) else None
         d["type"] = f"{stash.type.__module__}.{stash.type.__name__}"
         return d
 
diff --git a/example.html b/example.html
index 9c020be..eef26ad 100644
--- a/example.html
+++ b/example.html
@@ -7534,7 +7534,7 @@