Skip to content

Instantly share code, notes, and snippets.

@OhadRubin
OhadRubin / inverse_square_root_schedule.py
Created July 22, 2024 15:39
the inverse_square_root_schedule from PaliGemma and Scaling Vision Transformers
import numpy as np
import jax
import matplotlib.pyplot as plt
import jax.numpy as jnp
def inverse_square_root_schedule(
max_lr: float,
warmup_steps: int,
):
def schedule(count):
@OhadRubin
OhadRubin / inc_read_pickle.py
Created June 2, 2024 08:56
incrementally read a pickle file and show progress
import pickle
import numpy as np
from tqdm import tqdm
import os
# Create a large numpy array and save it to a pickle file
# a = np.random.random((1000, 1000))
a = np.random.random((40000,10000))
with open('large_array.pkl', 'wb') as f:
pickle.dump(a, f)
@OhadRubin
OhadRubin / docker how much space
Last active April 5, 2024 17:35
docker how much space
sudo ncdu /
sudo docker container ls -a --format '{{.ID}}:{{.Names}}' | xargs -I {} sh -c 'echo "Container {} ($(echo {} | cut -d: -f2)): $(sudo docker inspect --format "{{.GraphDriver.Data.MergedDir}}" $(echo {} | cut -d: -f1) | sed "s/\/merged$//") (Size: $(sudo du -sh $(sudo docker inspect --format "{{.GraphDriver.Data.MergedDir}}" $(echo {} | cut -d: -f1) | sed "s/\/merged$//") | cut -f1))"'
sudo docker image ls --format '{{.ID}}:{{.Repository}}:{{.Tag}}' | xargs -I {} sh -c 'echo "Image {} ($(echo {} | cut -d: -f2):$(echo {} | cut -d: -f3)): $(sudo docker inspect --format "{{.GraphDriver.Data.UpperDir}}" $(echo {} | cut -d: -f1) | sed "s/\/diff$//") (Size: $(sudo du -sh $(sudo docker inspect --format "{{.GraphDriver.Data.UpperDir}}" $(echo {} | cut -d: -f1) | sed "s/\/diff$//") | cut -f1))"'
@OhadRubin
OhadRubin / create_named_matrix.py
Created December 17, 2023 22:59
create_named_matrix
import more_itertools
import itertools
"""
>>> create_named_matrix(2,3,5)
array([[['0,0,0', '0,0,1', '0,0,2', '0,0,3', '0,0,4'],
['0,1,0', '0,1,1', '0,1,2', '0,1,3', '0,1,4'],
['0,2,0', '0,2,1', '0,2,2', '0,2,3', '0,2,4']],
[['1,0,0', '1,0,1', '1,0,2', '1,0,3', '1,0,4'],
['1,1,0', '1,1,1', '1,1,2', '1,1,3', '1,1,4'],
@OhadRubin
OhadRubin / function_namespace.txt
Created December 1, 2023 10:35
function_namespace.txt
namespace functions {
// Execute a block of Python code. This can be used to perform calculations, process data, or any other task that can be accomplished through Python code.
type python = (_: {
code: string,
}) => any;
// Create images from a text-only prompt. This tool is used to generate visual content based on detailed descriptions provided in text form.
type dalle = (_: {
size?: "1792x1024" | "1024x1024" | "1024x1792",
@OhadRubin
OhadRubin / sliding_window_eval.py
Last active January 27, 2024 11:50
sliding_window_eval.py
from more_itertools import windowed, repeat_last
import numpy as np
from more_itertools import grouper
input_ids = np.arange(65)
# input_ids = np.arange(4097)
width = 16
stride = 4
@OhadRubin
OhadRubin / setup_docker.sh
Last active March 27, 2024 06:13
setup_docker.sh
sudo apt-get update -y
# Add Docker's official GPG key:
sudo apt-get purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
@OhadRubin
OhadRubin / tpu.yaml
Created November 8, 2023 22:36
tpu openapi specification
openapi: 3.1.0
info:
contact:
name: StackQL Studios
url: https://github.com/stackql/google-discovery-to-openapi
email: info@stackql.io
title: Cloud TPU API
description: TPU API provides customers with access to Google TPU technology.
version: v2
x-discovery-doc-revision: '20231026'
@OhadRubin
OhadRubin / top_terms.html
Created October 16, 2023 06:02
top_terms.html
This file has been truncated, but you can view the full file.
<html>
<head><meta charset="utf-8" /></head>
<body>
<div> <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>
<script type="text/javascript">/**
* plotly.js v2.24.1
* Copyright 2012-2023, Plotly, Inc.
* All rights reserved.
* Licensed under the MIT license
*/
@OhadRubin
OhadRubin / combine_txt.md
Created September 28, 2023 13:13
combine_txt_prompt

Instructions

Your task: Combine multiple texts into one detailed document. Include every piece of information from each source. The goal is to avoid repetition while being thorough and exhaustive.

Essential steps:

  1. Organize structure carefully.
  2. Integrate all details.
  3. Avoid redundancy.

Warnings:

  • Be precise, not general.