Skip to content

Instantly share code, notes, and snippets.

View luciaquirke's full-sized avatar

Lucia Quirke luciaquirke

View GitHub Profile
@luciaquirke
luciaquirke / evaluate.py
Last active April 13, 2025 05:33
Evaluate sparse model
import os
from concurrent.futures import ProcessPoolExecutor
from functools import partial
import numpy as np
import pandas as pd
import torch
import torch.multiprocessing as mp
import torch.nn.functional as F
from datasets import load_dataset
@luciaquirke
luciaquirke / sparsify_hooks.py
Last active April 13, 2025 05:27
Sparsify Hooks
from contextlib import contextmanager
from functools import partial
from typing import Any
import torch.nn.functional as F
from torch import Tensor, nn
from transformers import PreTrainedModel
from sparsify import SparseCoder
@luciaquirke
luciaquirke / smollm2_corpus.py
Last active April 17, 2025 04:15
Sample from SmolLM2 Corpus (except I extracted the Stack-Edu download to a separate script to fix mp issue)
from functools import partial
import random
from argparse import ArgumentParser
from typing import Literal
import os
from glob import glob
import gzip
from datasets import (
load_dataset,
@luciaquirke
luciaquirke / reasoning_mix.py
Created January 24, 2025 02:12
Shuffle together web text and reasoning CoT datasets
from datasets import load_dataset, concatenate_datasets
from functools import partial
def process_map_fn(example, key):
return {"text": example[key]}
def flatten_and_format_conversations(example):
"""Flattens the conversations and formats them into a single text field."""
user_message = example["conversations"][0]["value"]