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 functools, time, jax, jax.numpy as jnp | |
jax.config.update("jax_default_matmul_precision", "tensorfloat32") | |
SQRT2_OVER_PI = 0.7978845608028654 | |
# ---------------------------------------------------------------------- | |
def gelu_fast(x): | |
u = SQRT2_OVER_PI * (x + 0.044715 * x * x * x) | |
return 0.5 * x * (1. + jnp.tanh(u)) |
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
#!/usr/bin/env -S uv run --script | |
# /// script | |
# requires-python = ">=3.12" | |
# dependencies = [ | |
# "jax==0.5.0", | |
# "jaxopt>=0.8.5", | |
# "optax>=0.2.4", | |
# "matplotlib>=3.10.1", | |
# "pyqt6>=6.9.0", # for matplotlib gui | |
# ] |
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
#!/usr/bin/env -S uv run --script | |
# /// script | |
# requires-python = ">=3.12" | |
# dependencies = [ | |
# "jax==0.5.0", | |
# "matplotlib>=3.10.1", | |
# "pyqt6>=6.9.0", # for matplotlib gui | |
# ] | |
# /// |
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
#!/usr/bin/env -S uv run --script --quiet | |
# /// script | |
# requires-python = ">=3.10" | |
# dependencies = [ | |
# "pyqt6", # For matplotlib backend | |
# "numpy", | |
# "matplotlib", | |
# "jax[cuda12]==0.5.2", # Change for CPU. | |
# ] | |
# /// |
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 numpy as np | |
import jax | |
import jax.numpy as jnp | |
import matplotlib.pyplot as plt | |
def init_mlp_params(layer_widths): | |
params = [] | |
for n_in, n_out in zip(layer_widths[:-1], layer_widths[1:]): | |
params.append( | |
dict(weights=np.random.normal(size=(n_in, n_out)) * np.sqrt(2/n_in), |
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
@ TOTAL=10000,DT=.1,xlo=0,xhi=1,ylo=-100,yhi=100 | |
@ NPLOT=1,XP1=w,YP1=V | |
@ MAXSTOR=10000000 | |
@ BOUNDS=100000 | |
@ dsmin=1e-5,dsmax=0.5,parmin=0,parmax=3,autoxmin=0,autoxmax=1,Ntst=150,Nmax=2000,Npr=500,Ds=0.02,EPSL=1e-7,EPSU=1e-7,EPSS=1e-7,*Y-axis=V | |
@ autoymax=100,autoymin=-100 |
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
print_macro: 105 ns/iter (+/- 20) | |
print_macro_locked_stdoutbench: 87 ns/iter (+/- 22) | |
direct_locked_stdout: 17 ns/iter (+/- 2) | |
direct_unlocked_stdout: 51 ns/iter (+/- 9) |
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
#![feature(test)] | |
extern crate test; | |
use test::Bencher; | |
const LARGE_NUMBER: i32 = 1_000_000; | |
#[bench] | |
fn bench_even_imperative(b: &mut Bencher) { | |
b.iter(|| { | |
let mut list = Vec::with_capacity(LARGE_NUMBER as usize / 2 + 1); |
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
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | |
// file at the top-level directory of this distribution and at | |
// http://rust-lang.org/COPYRIGHT. | |
// | |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
// option. This file may not be copied, modified, or distributed | |
// except according to those terms. |
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
#![feature(rt)] | |
#![feature(unmarked_api)] | |
use std::thread; | |
use std::any::Any; | |
use std::rt::unwind::set_panic_handler; | |
fn main() { | |
// Use the default handler | |
panic!("Something's wrong"); // Prints "thread '<main>' panicked at 'Something's wrong', /Users/yohai/code/panic_handlers_test.rs:10" |
NewerOlder