diff --git a/.gitignore b/.gitignore index f269d498..09db0094 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,4 @@ secrets.toml *Grokking *interp_on_model*.ipynb *other_solns -*gitignore -*analytics.json \ No newline at end of file +*gitignore \ No newline at end of file diff --git a/chapter0_fundamentals/instructions/pages/01_[0.1]_Ray_Tracing.py b/chapter0_fundamentals/instructions/pages/01_[0.1]_Ray_Tracing.py index cef42128..c462a6b8 100644 --- a/chapter0_fundamentals/instructions/pages/01_[0.1]_Ray_Tracing.py +++ b/chapter0_fundamentals/instructions/pages/01_[0.1]_Ray_Tracing.py @@ -14,6 +14,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -1958,4 +1964,9 @@ def raytrace_mesh_lambert_wireframe(triangles: t.Tensor, rays: t.Tensor, triangl """, unsafe_allow_html=True) -section_0() \ No newline at end of file +section_0() + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter0_fundamentals/instructions/pages/02_[0.2]_CNNs.py b/chapter0_fundamentals/instructions/pages/02_[0.2]_CNNs.py index 8f87e1dc..1fe1c306 100644 --- a/chapter0_fundamentals/instructions/pages/02_[0.2]_CNNs.py +++ b/chapter0_fundamentals/instructions/pages/02_[0.2]_CNNs.py @@ -51,13 +51,8 @@ def section_0(): - - - - ## Introduction - This section is designed to get you familiar with basic neural networks: how they are structured, the basic operations like linear layers and convolutions which go into making them, and why they work as well as they do. You'll be using libraries like `einops`, and functions like `torch.as_strided` to get a very low-level picture of how these operations work, which will help build up your overall understanding. Note that `torch.as_strided` isn't something which will come up explicitly in much of the rest of the course (unlike `einops`). The purpose of the stride exercises is more to give you an appreciation for what's going on under the hood, so that we can build layers of abstraction on top of that during the rest of this week (and by extension this course). I see this as analogous to how [many CS courses](https://cs50.harvard.edu/x/2023/) start by teaching you about languages like C and concepts like pointers and memory management before moving on to higher-level langauges like Python which abstract away these details. The hope is that when you get to the later sections of the course, you'll have the tools to understand them better. diff --git a/chapter0_fundamentals/instructions/pages/03_[0.3]_ResNets.py b/chapter0_fundamentals/instructions/pages/03_[0.3]_ResNets.py index 18ebee79..96d18c79 100644 --- a/chapter0_fundamentals/instructions/pages/03_[0.3]_ResNets.py +++ b/chapter0_fundamentals/instructions/pages/03_[0.3]_ResNets.py @@ -14,6 +14,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -2161,3 +2167,9 @@ def page(): func() page() + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter0_fundamentals/instructions/pages/04_[0.4]_Optimization.py b/chapter0_fundamentals/instructions/pages/04_[0.4]_Optimization.py index 6cb10e7f..0ece0a1e 100644 --- a/chapter0_fundamentals/instructions/pages/04_[0.4]_Optimization.py +++ b/chapter0_fundamentals/instructions/pages/04_[0.4]_Optimization.py @@ -14,6 +14,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown( @@ -1874,3 +1880,9 @@ def page(): func() page() + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter0_fundamentals/instructions/pages/05_[0.5]_Backprop.py b/chapter0_fundamentals/instructions/pages/05_[0.5]_Backprop.py index 0ff4be1f..992f421c 100644 --- a/chapter0_fundamentals/instructions/pages/05_[0.5]_Backprop.py +++ b/chapter0_fundamentals/instructions/pages/05_[0.5]_Backprop.py @@ -14,6 +14,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -3589,3 +3595,9 @@ def page(): func() page() + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git "a/chapter0_fundamentals/instructions/pages/99_\360\237\244\226_Chatbot.py" "b/chapter0_fundamentals/instructions/pages/99_\360\237\244\226_Chatbot.py" index fa141bcb..c877e39e 100644 --- "a/chapter0_fundamentals/instructions/pages/99_\360\237\244\226_Chatbot.py" +++ "b/chapter0_fundamentals/instructions/pages/99_\360\237\244\226_Chatbot.py" @@ -23,6 +23,12 @@ sys.path.append(str(root_path)) sys.path.append(str(root_path.parent)) +ANALYTICS_PATH = root_path / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + from chatbot import answer_question, Embedding, EmbeddingGroup files = (root_path / "pages").glob("*.py") @@ -172,4 +178,9 @@ # sort chronologically after top-k # block signature -# %% + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter0_fundamentals/instructions/pages/analytics.json b/chapter0_fundamentals/instructions/pages/analytics.json new file mode 100644 index 00000000..e69de29b diff --git a/chapter1_transformers/instructions/pages/01_[1.1]_Transformer_from_Scratch.py b/chapter1_transformers/instructions/pages/01_[1.1]_Transformer_from_Scratch.py index 36c852d6..edde6201 100644 --- a/chapter1_transformers/instructions/pages/01_[1.1]_Transformer_from_Scratch.py +++ b/chapter1_transformers/instructions/pages/01_[1.1]_Transformer_from_Scratch.py @@ -20,6 +20,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -4060,3 +4066,9 @@ def page(): func() page() + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter1_transformers/instructions/pages/02_[1.2]_Intro_to_Mech_Interp.py b/chapter1_transformers/instructions/pages/02_[1.2]_Intro_to_Mech_Interp.py index fb7e6d1a..37cb0f9c 100644 --- a/chapter1_transformers/instructions/pages/02_[1.2]_Intro_to_Mech_Interp.py +++ b/chapter1_transformers/instructions/pages/02_[1.2]_Intro_to_Mech_Interp.py @@ -22,6 +22,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -3753,3 +3759,9 @@ def page(): func() page() + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter1_transformers/instructions/pages/03_[1.3]_Indirect_Object_Identification.py b/chapter1_transformers/instructions/pages/03_[1.3]_Indirect_Object_Identification.py index b4b25694..a10c7456 100644 --- a/chapter1_transformers/instructions/pages/03_[1.3]_Indirect_Object_Identification.py +++ b/chapter1_transformers/instructions/pages/03_[1.3]_Indirect_Object_Identification.py @@ -19,6 +19,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -4449,3 +4455,9 @@ def page(): func() page() + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter1_transformers/instructions/pages/04_[1.4]_Balanced_Bracket_Classifier.py b/chapter1_transformers/instructions/pages/04_[1.4]_Balanced_Bracket_Classifier.py index ee619934..13e4d78f 100644 --- a/chapter1_transformers/instructions/pages/04_[1.4]_Balanced_Bracket_Classifier.py +++ b/chapter1_transformers/instructions/pages/04_[1.4]_Balanced_Bracket_Classifier.py @@ -19,6 +19,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -2508,3 +2514,9 @@ def page(): func() page() + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter1_transformers/instructions/pages/05_[1.5]_Grokking_and_Modular_Arithmetic.py b/chapter1_transformers/instructions/pages/05_[1.5]_Grokking_and_Modular_Arithmetic.py index 6376f1b7..e2a49286 100644 --- a/chapter1_transformers/instructions/pages/05_[1.5]_Grokking_and_Modular_Arithmetic.py +++ b/chapter1_transformers/instructions/pages/05_[1.5]_Grokking_and_Modular_Arithmetic.py @@ -19,6 +19,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -3265,3 +3271,8 @@ def page(): func() page() + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter1_transformers/instructions/pages/06_[1.6]_OthelloGPT.py b/chapter1_transformers/instructions/pages/06_[1.6]_OthelloGPT.py index 0aa546cf..51e86255 100644 --- a/chapter1_transformers/instructions/pages/06_[1.6]_OthelloGPT.py +++ b/chapter1_transformers/instructions/pages/06_[1.6]_OthelloGPT.py @@ -19,6 +19,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -3184,3 +3190,8 @@ def page(): func() page() + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter1_transformers/instructions/pages/07_[1.7]_Toy_Models_of_Superposition.py b/chapter1_transformers/instructions/pages/07_[1.7]_Toy_Models_of_Superposition.py index c8803009..ee997f7d 100644 --- a/chapter1_transformers/instructions/pages/07_[1.7]_Toy_Models_of_Superposition.py +++ b/chapter1_transformers/instructions/pages/07_[1.7]_Toy_Models_of_Superposition.py @@ -19,6 +19,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0(): st.sidebar.markdown(r""" @@ -1406,4 +1412,9 @@ def compute_dimensionality( * [Open questions](https://transformer-circuits.pub/2022/toy_model/index.html#open-questions) from the original Anthropic paper. What do you think about them? Do any seem tractible to you? """, unsafe_allow_html=True) -section_0() \ No newline at end of file +section_0() + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter1_transformers/instructions/pages/08_Reference_Page.py b/chapter1_transformers/instructions/pages/08_Reference_Page.py index c572bc98..28cf87ba 100644 --- a/chapter1_transformers/instructions/pages/08_Reference_Page.py +++ b/chapter1_transformers/instructions/pages/08_Reference_Page.py @@ -19,6 +19,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + st.sidebar.markdown(r""" ## Table of Contents @@ -400,4 +406,10 @@ def forward(self, x): Your workflow might use all three of these, e.g. working in VSCode using a combination of notebooks for exploratory analysis and Python files for writing functions that you'll import into your notebooks, then finally converting your notebooks to Colabs to publish your results. -""", unsafe_allow_html=True) \ No newline at end of file +""", unsafe_allow_html=True) + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter1_transformers/instructions/pages/09_Monthly_Algorithmic_Problems.py b/chapter1_transformers/instructions/pages/09_Monthly_Algorithmic_Problems.py index bb98e4bf..e886b287 100644 --- a/chapter1_transformers/instructions/pages/09_Monthly_Algorithmic_Problems.py +++ b/chapter1_transformers/instructions/pages/09_Monthly_Algorithmic_Problems.py @@ -19,6 +19,12 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + def section_0_july(): st.sidebar.markdown(r""" @@ -1307,3 +1313,9 @@ def page(): func() page() + + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git "a/chapter1_transformers/instructions/pages/99_\360\237\244\226_Chatbot.py" "b/chapter1_transformers/instructions/pages/99_\360\237\244\226_Chatbot.py" index 8198c8fe..3cb08c20 100644 --- "a/chapter1_transformers/instructions/pages/99_\360\237\244\226_Chatbot.py" +++ "b/chapter1_transformers/instructions/pages/99_\360\237\244\226_Chatbot.py" @@ -28,6 +28,12 @@ if str(instructions_dir) not in sys.path: sys.path.append(str(instructions_dir)) os.chdir(instructions_dir) +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + from chatbot import answer_question, Embedding, EmbeddingGroup files = (instructions_dir / "pages").glob("*.py") @@ -176,4 +182,9 @@ # sort chronologically after top-k # block signature -# %% \ No newline at end of file +# %% + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter1_transformers/instructions/pages/analytics.json b/chapter1_transformers/instructions/pages/analytics.json new file mode 100644 index 00000000..b65e86f8 --- /dev/null +++ b/chapter1_transformers/instructions/pages/analytics.json @@ -0,0 +1 @@ +{"loaded_from_firestore": false, "total_pageviews": 3, "total_script_runs": 11, "total_time_seconds": 128.336865, "per_day": {"days": ["2023-08-08", "2023-08-09"], "pageviews": [0, 3], "script_runs": [0, 11]}, "widgets": {}, "start_time": "09 Aug 2023, 17:43:29"} \ No newline at end of file diff --git a/chapter1_transformers/instructions/requirements.txt b/chapter1_transformers/instructions/requirements.txt index 176d817d..108d31c5 100644 --- a/chapter1_transformers/instructions/requirements.txt +++ b/chapter1_transformers/instructions/requirements.txt @@ -4,4 +4,5 @@ openai plotly matplotlib scipy -torch \ No newline at end of file +torch +streamlit-analytics \ No newline at end of file diff --git a/chapter2_rl/instructions/pages/01_[2.1]_Intro_to_RL.py b/chapter2_rl/instructions/pages/01_[2.1]_Intro_to_RL.py index 5fb31bb2..6b055aab 100644 --- a/chapter2_rl/instructions/pages/01_[2.1]_Intro_to_RL.py +++ b/chapter2_rl/instructions/pages/01_[2.1]_Intro_to_RL.py @@ -14,6 +14,13 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + + def section_0(): st.sidebar.markdown(r""" @@ -1614,3 +1621,8 @@ def page(): func() page() + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter2_rl/instructions/pages/02_[2.2]_Q-Learning_and_DQN.py b/chapter2_rl/instructions/pages/02_[2.2]_Q-Learning_and_DQN.py index 4b4f3e64..b408adb2 100644 --- a/chapter2_rl/instructions/pages/02_[2.2]_Q-Learning_and_DQN.py +++ b/chapter2_rl/instructions/pages/02_[2.2]_Q-Learning_and_DQN.py @@ -14,6 +14,13 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + + def section_0(): st.sidebar.markdown(r""" @@ -2518,3 +2525,8 @@ def page(): func() page() + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter2_rl/instructions/pages/03_[2.3]_PPO.py b/chapter2_rl/instructions/pages/03_[2.3]_PPO.py index 447f93c0..05fb82c9 100644 --- a/chapter2_rl/instructions/pages/03_[2.3]_PPO.py +++ b/chapter2_rl/instructions/pages/03_[2.3]_PPO.py @@ -14,6 +14,13 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + + def section_0(): st.sidebar.markdown(r""" @@ -2669,3 +2676,8 @@ def page(): func() page() + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter2_rl/instructions/pages/04_[2.4]_RLHF.py b/chapter2_rl/instructions/pages/04_[2.4]_RLHF.py index 6538110e..674babde 100644 --- a/chapter2_rl/instructions/pages/04_[2.4]_RLHF.py +++ b/chapter2_rl/instructions/pages/04_[2.4]_RLHF.py @@ -14,6 +14,13 @@ import platform is_local = (platform.processor() != "") +ANALYTICS_PATH = instructions_dir / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + + def section_0(): st.sidebar.markdown(r""" @@ -1201,3 +1208,8 @@ def page(): func() page() + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git "a/chapter2_rl/instructions/pages/99_\360\237\244\226_Chatbot.py" "b/chapter2_rl/instructions/pages/99_\360\237\244\226_Chatbot.py" index b5a1d071..c79b9b44 100644 --- "a/chapter2_rl/instructions/pages/99_\360\237\244\226_Chatbot.py" +++ "b/chapter2_rl/instructions/pages/99_\360\237\244\226_Chatbot.py" @@ -25,6 +25,13 @@ from chatbot import answer_question, Embedding, EmbeddingGroup +ANALYTICS_PATH = root_path / "pages/analytics.json" +import streamlit_analytics +streamlit_analytics.start_tracking( + load_from_json=ANALYTICS_PATH.resolve(), +) + + files = (root_path / "pages").glob("*.py") names = [f.stem for f in files if f.stem[0].isdigit() and "Chatbot" not in f.stem] names = [name.split("]")[1].replace("_", " ").strip() for name in names] @@ -173,3 +180,8 @@ # block signature # %% + +streamlit_analytics.stop_tracking( + unsafe_password=st.secrets["analytics_password"], + save_to_json=ANALYTICS_PATH.resolve(), +) \ No newline at end of file diff --git a/chapter2_rl/instructions/pages/analytics.json b/chapter2_rl/instructions/pages/analytics.json new file mode 100644 index 00000000..e69de29b diff --git a/chapter2_rl/instructions/requirements.txt b/chapter2_rl/instructions/requirements.txt index 176d817d..108d31c5 100644 --- a/chapter2_rl/instructions/requirements.txt +++ b/chapter2_rl/instructions/requirements.txt @@ -4,4 +4,5 @@ openai plotly matplotlib scipy -torch \ No newline at end of file +torch +streamlit-analytics \ No newline at end of file