Skip to content

Instantly share code, notes, and snippets.

View levskaya's full-sized avatar

Anselm Levskaya levskaya

View GitHub Profile
@levskaya
levskaya / ieee754.js
Created December 30, 2011 22:45
IEEE-754 bit access / conversion in javascript
/* from: http://cautionsingularityahead.blogspot.com/2010/04/javascript-and-ieee754-redux.html */
function toIEEE754(v, ebits, fbits) {
var bias = (1 << (ebits - 1)) - 1;
// Compute sign, exponent, fraction
var s, e, f;
if (isNaN(v)) {
e = (1 << bias) - 1; f = 1; s = 0;
/**
http://closure-library.googlecode.com/svn-history/r440/trunk/third_party/closure/goog/jpeg_encoder/jpeg_encoder_basic.js
* @license
Copyright (c) 2008, Adobe Systems Incorporated
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
-- For anyone who liked the PRIME DETECTOR puzzle included in some of the early access
-- builds of TIS-100...
-- INSTALLATION: Copy everything in this file. Open TIS-100. Go to the SPECIFICATION
-- EDITOR. Click on IMPORT SPECIFICATION FROM CLIPBOARD. Done!
-- The function get_name() should return a single string that is the name of the puzzle.
--
function get_name()
return "PRIME DETECTOR"
@levskaya
levskaya / top-k-top-p.py
Created May 3, 2019 23:54 — forked from thomwolf/top-k-top-p.py
Sample the next token from a probability distribution using top-k and/or nucleus (top-p) sampling
def top_k_top_p_filtering(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')):
""" Filter a distribution of logits using top-k and/or nucleus (top-p) filtering
Args:
logits: logits distribution shape (..., vocabulary size)
top_k >0: keep only top k tokens with highest probability (top-k filtering).
top_p >0.0: keep the top tokens with cumulative probability >= top_p (nucleus filtering).
"""
top_k = min(top_k, logits.size(-1)) # Safety check
if top_k > 0:
# Remove all tokens with a probability less than the last token of the top-k
@levskaya
levskaya / gist:d8bd85e188a9836ad9107d874965d94c
Created March 5, 2020 05:45
tensorflow_dataset import bug
In [2]: import tensorflow_datasets as tfds
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-46a8a2031c9c> in <module>
----> 1 import tensorflow_datasets as tfds
@levskaya
levskaya / jax_colab_utils.py
Last active November 16, 2022 20:22
JAX Colab Memory/Cache Utilities
import gc
import re
import jax
from jax import numpy as jnp
import numpy as np
from IPython import display
import pandas as pd
def natural_keys(text):
@levskaya
levskaya / papers.md
Created December 16, 2021 05:22 — forked from pdarragh/papers.md
Approachable PL Papers for Undergrads

Approachable PL Papers for Undergrads

On September 28, 2021, I asked on Twitter:

PL Twitter:

you get to recommend one published PL paper for an undergrad to read with oversight by someone experienced. the paper should be interesting, approachable, and (mostly) self-contained.

what paper do you recommend?

from __future__ import annotations
from contextlib import contextmanager
from typing import NamedTuple, Callable, Optional, Any
import numpy as np
Array = Any
class Node(NamedTuple):
vjp: Optional[Callable]
parents: List[Node]