This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Script to anonymize specific terms in files by replacing them with 'XXXX'. | |
Usage: | |
python anonymize.py <input_dir> <output_dir> <terms_to_anonymize> | |
Arguments: | |
input_dir: Directory containing files to anonymize | |
output_dir: Directory where anonymized files will be written |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Utilities for managing torch device """ | |
import torch | |
from contextlib import contextmanager | |
from typing import Generator | |
def get_default_device() -> str: | |
if torch.cuda.is_available(): | |
return "cuda" | |
elif torch.backends.mps.is_available() and torch.backends.mps.is_built(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Useful design patterns and abstractions""" | |
from typing import Generic, TypeVar | |
T = TypeVar("T") | |
# Reference: https://stackoverflow.com/a/7346105 | |
class Singleton(Generic[T]): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Utilities for working with dataframes | |
import pandas as pd | |
from IPython.display import display, HTML | |
def flatten_dict(nested_dict, prefix="", delimiter="."): | |
""" Flattens a nested dictionary """ | |
flattened = {} | |
for key, value in nested_dict.items(): | |
new_key = f"{prefix}{key}" | |
if isinstance(value, dict): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>sp|P49383|ADH2_KLULA Alcohol dehydrogenase 2 OS=Kluyveromyces lactis (strain ATCC 8585 / CBS 2359 / DSM 70799 / NBRC 1267 / NRRL Y-1140 / WM37) OX=284590 GN=ADH2 PE=3 SV=2 | |
MSIPETQKGVIFYENGGELQYKDIPVPKPKANELLINVKYSGVCHTDLHAWKGDWPLPTK | |
LPLVGGHEGAGVVVAMGENVKGWNIGDFAGIKWLNGSCMSCEYCELSNESNCPDADLSGY | |
THDGSFQQYATADAVQAARIPKGTDLAEVAPILCAGVTVYKALKSADLKAGDWVAISGAC | |
GGLGSLAIQYAKAMGYRVLGIDTGAEKAKLFKELGGEYFVDYAVSKDLIKEIVDATNGGA | |
HGVINVSVSEFAIEQSTNYVRSNGTVVLVGLPRDAKCKSDVFTQVVKSVSIVGSYVGNRA | |
DTREALDFFARGLVHAPIKIVGLSELADVYDKMVKGEIVGRYVVDTSK | |
>sp|N4WW42|RED3_COCH4 Dehydrogenase RED3 OS=Cochliobolus heterostrophus (strain C4 / ATCC 48331 / race T) OX=665024 GN=RED3 PE=3 SV=1 | |
MGLVKGNCGCYWGIKGHWSRNCSPVCEIANKNYYSRRGIAPRRTFWSVSNKSLVHLDANS | |
LMIDYENVFYYTTDITSNKAIIESSERIRQDHGNPSVLINNAGVANGKTILEESEDERRR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformer_lens import HookedSAEConfig, HookedSAE | |
from sae_lens import SparseAutoencoder | |
from sae_lens.training.train_sae_on_language_model import LanguageModelSAERunnerConfig | |
def sl_sae_cfg_to_hooked_sae_cfg( | |
resid_sae_cfg: LanguageModelSAERunnerConfig, | |
) -> HookedSAEConfig: | |
new_cfg = { | |
"d_sae": resid_sae_cfg.d_sae, | |
"d_in": resid_sae_cfg.d_in, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#$ -N test_script | |
#$ -o /home/$USER/logs/ | |
#$ -e /home/$USER/logs/ | |
# Set up a web hook here, SAVE SETTINGS, then paste URL | |
# https://api.slack.com/messaging/webhooks | |
SLACK_WEBHOOK_URL="Replace Me" | |
# Find Your Slack User ID |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" A script to open a list of SAE features in Neuronpedia in your web browser. | |
Usage: | |
1. Clone this gist. | |
2. Change LAYER, FEATURES to whatever you want. | |
3. Run the script. | |
""" | |
import json | |
import urllib.parse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: Promise.all([import('https://unpkg.com/turndown@6.0.0?module'), import('https://unpkg.com/@tehshrike/readability@0.2.0'), ]).then(async ([{ | |
default: Turndown | |
}, { | |
default: Readability | |
}]) => { | |
/* Optional vault name */ | |
const vault = ""; | |
/* Optional folder name such as "Clippings/" */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Usage: | |
1. python -m cProfile -o [path/to/output.profile] [path/to/script.py] | |
2. python print_pstats.py -i [path/to/output.profile] [optional args] | |
By default prints the top 20 functions, sorted by total time spent in function | |
""" | |
import pstats | |
import argparse | |
from pstats import SortKey |
NewerOlder