This file contains 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
import csv | |
from datetime import datetime, timedelta | |
START_DATE = datetime.today() | |
WEEKS = 15 | |
INITIAL_DISTANCE = 35 | |
MAX_INCREASE_RATE = 0.10 | |
PARK_RUN_DISTANCE = 8 | |
INCREASE_RATE = 0.05 |
This file contains 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 flask import Flask, render_template, request, redirect | |
import jsonlines | |
import os | |
app = Flask(__name__) | |
@app.route("/") | |
def home(): | |
default_fname = "tmp/evallogs/230807123401PG6IQKIY_gpt-3.5-turbo-16k,gpt-3.5-turbo-16k_make-me-say.jsonl" |
This file contains 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 teeny tiny compiler!""" | |
import re | |
from typing import List, Tuple | |
from dataclasses import dataclass | |
TOKEN_TYPES = [ | |
("def", r"\bdef\b"), | |
("end", r"\bend\b"), | |
("identifier", r"\b[a-zA-Z]+\b"), |
This file contains 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
def sample(seq: Sequence, k: int, include: Union[None, set] = None, exclude: Union[None, set] = None) -> Sequence: | |
"""Samples `k` items from `seq` without replacement, optionally including or excluding items.""" | |
# pre-condition | |
assert k >= 0, "Number of items to sample must be non-negative" | |
assert k <= len(seq), f"Cannot sample {k} items without replacement from a sequence with {len(seq)} items" | |
if include is None: | |
include = set() | |
This file contains 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
class DictDataset(torch.utils.data.Dataset): | |
"""Makes a dataset from a dictionary of tensors""" | |
def __init__(self, inputs: Dict[str, Tensor]): | |
assert len(inputs) > 0, "inputs must be non-empty" | |
keys = list(inputs.keys()) | |
key = keys[0] | |
self._length = inputs[key].shape[0] | |
This file contains 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
# This hook is particularly useful when ablating layers | |
class ContextHook: | |
def __init__(self, layer): | |
self.layer = layer | |
def __enter__(self): | |
self.handle = self.layer.register_forward_hook(self.hook) | |
return self |
This file contains 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
class StatefulHook: | |
def __init__(self): | |
self.module = None | |
self.input = None | |
self.output = None | |
def __call__(self, module, input, output): | |
self.module = module | |
self.input = input | |
self.output = output |