Skip to content

Instantly share code, notes, and snippets.

@levskaya
levskaya / jax_colab_utils.py
Last active Sep 1, 2020
JAX Colab Memory/Cache Utilities
View jax_colab_utils.py
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):
View gist:d8bd85e188a9836ad9107d874965d94c
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 / top-k-top-p.py
Created May 3, 2019 — 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
View top-k-top-p.py
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
View 19392494.lua
-- 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"
View gist:5565633
/**
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:
@levskaya
levskaya / ieee754.js
Created Dec 30, 2011
IEEE-754 bit access / conversion in javascript
View ieee754.js
/* 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;