Extracting and visualizing hidden activations and computational graphs of PyTorch models with TorchLens.
Journal
Scientific reports
ISSN: 2045-2322
Titre abrégé: Sci Rep
Pays: England
ID NLM: 101563288
Informations de publication
Date de publication:
01 09 2023
01 09 2023
Historique:
received:
01
05
2023
accepted:
16
08
2023
medline:
4
9
2023
pubmed:
2
9
2023
entrez:
1
9
2023
Statut:
epublish
Résumé
Deep neural network models (DNNs) are essential to modern AI and provide powerful models of information processing in biological neural networks. Researchers in both neuroscience and engineering are pursuing a better understanding of the internal representations and operations that undergird the successes and failures of DNNs. Neuroscientists additionally evaluate DNNs as models of brain computation by comparing their internal representations to those found in brains. It is therefore essential to have a method to easily and exhaustively extract and characterize the results of the internal operations of any DNN. Many models are implemented in PyTorch, the leading framework for building DNN models. Here we introduce TorchLens, a new open-source Python package for extracting and characterizing hidden-layer activations in PyTorch models. Uniquely among existing approaches to this problem, TorchLens has the following features: (1) it exhaustively extracts the results of all intermediate operations, not just those associated with PyTorch module objects, yielding a full record of every step in the model's computational graph, (2) it provides an intuitive visualization of the model's complete computational graph along with metadata about each computational step in a model's forward pass for further analysis, (3) it contains a built-in validation procedure to algorithmically verify the accuracy of all saved hidden-layer activations, and (4) the approach it uses can be automatically applied to any PyTorch model with no modifications, including models with conditional (if-then) logic in their forward pass, recurrent models, branching models where layer outputs are fed into multiple subsequent layers in parallel, and models with internally generated tensors (e.g., injections of noise). Furthermore, using TorchLens requires minimal additional code, making it easy to incorporate into existing pipelines for model development and analysis, and useful as a pedagogical aid when teaching deep learning concepts. We hope this contribution will help researchers in AI and neuroscience understand the internal representations of DNNs.
Identifiants
pubmed: 37658079
doi: 10.1038/s41598-023-40807-0
pii: 10.1038/s41598-023-40807-0
pmc: PMC10474256
doi:
Types de publication
Journal Article
Research Support, N.I.H., Extramural
Langues
eng
Sous-ensembles de citation
IM
Pagination
14375Subventions
Organisme : NEI NIH HHS
ID : F32 EY033654
Pays : United States
Commentaires et corrections
Type : UpdateOf
Informations de copyright
© 2023. Springer Nature Limited.
Références
Front Syst Neurosci. 2008 Nov 24;2:4
pubmed: 19104670
Nat Neurosci. 2016 Mar;19(3):356-65
pubmed: 26906502
Elife. 2023 Aug 23;12:
pubmed: 37610302
Proc Natl Acad Sci U S A. 2014 Jun 10;111(23):8619-24
pubmed: 24812127
J Cogn Neurosci. 2021 Sep 1;33(10):2044-2064
pubmed: 34272948
Neuron. 2018 May 2;98(3):630-644.e16
pubmed: 29681533
PLoS Comput Biol. 2020 Oct 2;16(10):e1008215
pubmed: 33006992
Nat Commun. 2021 Apr 6;12(1):2065
pubmed: 33824315
Sci Rep. 2022 Sep 29;12(1):16327
pubmed: 36175483
Proc Natl Acad Sci U S A. 2021 Jan 19;118(3):
pubmed: 33431673
Sci Adv. 2023 Jun 9;9(23):eadh0478
pubmed: 37294753
Nature. 2015 Feb 26;518(7540):529-33
pubmed: 25719670
PLoS Comput Biol. 2014 Apr 17;10(4):e1003553
pubmed: 24743308
J Comput Aided Mol Des. 2016 Aug;30(8):595-608
pubmed: 27558503
PLoS Comput Biol. 2014 Nov 06;10(11):e1003915
pubmed: 25375136
Neuroimage. 2022 Dec 1;264:119728
pubmed: 36334814
Annu Rev Vis Sci. 2015 Nov 24;1:417-446
pubmed: 28532370
Front Neuroinform. 2021 Sep 22;15:679838
pubmed: 34630062
Neuron. 2021 Feb 17;109(4):724-738.e7
pubmed: 33326755