This file contains hidden or 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
| use chrono::{DateTime, Duration, Utc}; | |
| #[derive(Debug, Clone, Copy)] | |
| pub struct Estimation { | |
| pub d: f64, // Difference in seconds | |
| pub a: f64, // Uncertainty | |
| } | |
| pub fn estimate_offset(s: DateTime<Utc>, r: DateTime<Utc>, c: DateTime<Utc>) -> Estimation { | |
| // d = c - (r + s) / 2 |
This file contains hidden or 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
| use std::time::Instant; | |
| #[derive(Debug, Clone, Copy)] | |
| pub struct Estimation { | |
| pub d: f64, | |
| pub a: f64, | |
| } | |
| pub fn estimate_offset(s: f64, r: f64, c: f64) -> Estimation { | |
| Estimation { |
This file contains hidden or 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
| use nalgebra::{DMatrix, DVector}; | |
| // Import the Rng trait so that .gen() is available on thread_rng() | |
| use rand_0_8_5::Rng; | |
| /// 1. Computes standard Softmax Attention Y | |
| fn compute_softmax_attention(q: &DMatrix<f64>, k: &DMatrix<f64>, v: &DMatrix<f64>) -> DMatrix<f64> { | |
| let mut scores = q * k.transpose(); | |
| for i in 0..scores.nrows() { | |
| let mut row = scores.row_mut(i); |
This file contains hidden or 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
| fn main() { | |
| let mut nonces = vec![0u128]; | |
| let mut counter = 0u64; | |
| nonces.pop(); | |
| // First Gap: 1.5 x 10^9 to 2.0 x 10^9 | |
| //counter += (2.0e9 - 1.5e9) as u64; | |
| for nonce in 1_500/*_000_000*/..=3_000/*_000_000*/ { | |
| nonces.push(nonce*1_000_000); | |
| counter = counter+1; |
This file contains hidden or 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
| use sha2::{Digest, Sha256}; | |
| use std::collections::HashSet; | |
| use rand_0_8_5/*_0_9_2*/::{RngCore, thread_rng}; | |
| /// For a 256-bit security level, we need 256 pairs of preimages (512 total). | |
| const BITS: usize = 256; | |
| /// The Private Key: Two lists (Secret-0 and Secret-1). | |
| struct PrivateKey { | |
| pairs: [[[u8; 32]; BITS]; 2], |
This file contains hidden or 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
| var spawn = require('child_process').spawn; | |
| // spawn_detached(file, [args = []], [options = {}], [callback]); | |
| function spawn_detached(file, args, options, callback) { | |
| if (arguments.length == 2 && | |
| typeof args == 'function') { | |
| callback = arguments[1]; | |
| args = undefined; | |
| } |
This file contains hidden or 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
| """ | |
| The most atomic way to train and inference a GPT in pure, dependency-free Python. | |
| This file is the complete algorithm. | |
| Everything else is just efficiency. | |
| @karpathy | |
| """ | |
| import os # os.path.exists | |
| import math # math.log, math.exp |
This file contains hidden or 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
| use std::env; | |
| use std::fs::File; | |
| use std::io::{BufRead, BufReader, Read, Write, Result}; | |
| /* ------------------------------------------------------------------ */ | |
| /* Model hyper-parameters */ | |
| /* ------------------------------------------------------------------ */ | |
| const N_EMBD: usize = 32; | |
| const N_HEAD: usize = 4; | |
| const N_LAYER: usize = 1; |
This file contains hidden or 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
| // Dependencies used: tokio, hyper, hyper-util, http-body-util, serde, serde_json, url | |
| use http_body_util::Full; | |
| use hyper::body::Bytes; | |
| use hyper::server::conn::http1; | |
| use hyper::service::service_fn; | |
| use hyper::{Request, Response, StatusCode}; | |
| use hyper_util::rt::TokioIo; | |
| use std::net::SocketAddr; | |
| use std::sync::atomic::{AtomicBool, Ordering}; | |
| use std::sync::Arc; |
This file contains hidden or 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
| use ndarray::Array1; | |
| use rand::Rng; | |
| // The playground often requires RngExt for sampling distributions | |
| use rand::distr::{Distribution, StandardUniform}; | |
| #[derive(Debug)] | |
| enum Activation { | |
| Logistic, | |
| ReLU, | |
| Linear, |
NewerOlder