Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions circuit_sparsity/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,13 +1485,8 @@ def _maybe_item(x):
cols = st.columns([1, 1])
model_config = viz_data["importances"]["beeg_model_config"]
with cols[0]:
cols2 = st.columns([1, 2, 1])
cols2 = st.columns([2, 1])
with cols2[0]:
use_pca = st.toggle(
"PCA components",
value=False,
)
with cols2[1]:
chidx = st.selectbox(
"res channel index",
options=[
Expand All @@ -1502,14 +1497,10 @@ def _maybe_item(x):
)
chidx = int(chidx.split(" ")[0])

with cols2[2]:
with cols2[1]:
st.text(f"encname: {model_config.tokenizer_name}")

if use_pca:
U, S, V = get_embed_weights_pca(model_path, q=100)
embsort = U[:, chidx].cpu().sort(descending=True)
else:
embsort = embed_weight[:, chidx].sort(descending=True)
embsort = embed_weight[:, chidx].sort(descending=True)

def _filter_embsort(xs):
return [
Expand Down Expand Up @@ -1588,12 +1579,6 @@ def _filter_embsort(xs):
status_placeholder.html("<pre>ready<br>&nbsp;</pre>")


@cache("get_embed_weights_pca_v1")
def get_embed_weights_pca(model_path, q):
wte = get_embed_weights(model_path).float()
return torch.pca_lowrank(wte, niter=10, q=q)


@cache("get_embed_weights_v1")
def get_embed_weights(model_path):
return get_model_weights(model_path, lambda x: x["transformer.wte.weight"]).half()
Expand Down Expand Up @@ -1714,5 +1699,3 @@ def treemap(f, x):
st.set_page_config(page_title="Circuit viz", layout="wide")

main()