Skip to content

Instantly share code, notes, and snippets.

View ToluClassics's full-sized avatar
🏠
Working from home

Ogundepo Odunayo ToluClassics

🏠
Working from home
View GitHub Profile
@djamelz
djamelz / aliasSwitching.py
Created October 12, 2015 21:09
Elasticsearch Alias switching in python => restore the new one, close the latest and delete the olders (based on name versioning index_name_xxx, index_name_xxy for index name and index_name for alias)
from elasticsearch import Elasticsearch
es = Elasticsearch(hosts=['es-host:9200'], timeout=600) #long timeout for the restore operation
snapshotName='index_name_20151012140502'
alias = es.indices.get_alias('index_name').keys()[0] if es.indices.exists_alias(name='index_name') else ''
indices = filter(lambda x: x.startswith('index_name'), es.indices.get_aliases())
indices.sort()
print 'restore repository'
es.snapshot.restore(repository='repository_name', snapshot=snapshotName, body ='{ "ignore_unavailable": "true", "include_global_state": false}', wait_for_completion=True)
if (len(alias) > 1):
@yang-zhang
yang-zhang / binary_cross_entropy_with_logits.ipynb
Created October 16, 2018 20:46
binary cross entropy implementation in pytorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zhensongren
zhensongren / uninstall_python3.MD
Last active July 5, 2024 09:54
How to uninstall python3 from Ubuntu

To list all python versions in default locations

ls /usr/bin/python*

To remove just python3 package

sudo apt-get remove python3.5

plus it's dependent packages

sudo apt-get remove --auto-remove python3.5

plus configuration and/or data files of python3

sudo apt-get purge python3.5

@skye
skye / tpu_topology_env_vars.py
Last active July 10, 2024 16:07
You can use these environment variables to run a Python process on a subset of the TPU cores on a Cloud TPU VM. This allows running multiple TPU processes at the same time, since only one process can access a given TPU chip at a time. Note that on TPU v2 and v3, 1 TPU chip = 2 TpuDevice as reported by `jax.devices()` (8 devices total). On v4, 1 …
# ==== Non-communicating processes
# 4x 1 chip per process:
os.environ["TPU_CHIPS_PER_PROCESS_BOUNDS"] = "1,1,1"
os.environ["TPU_PROCESS_BOUNDS"] = "1,1,1"
# Different per process:
os.environ["TPU_VISIBLE_DEVICES"] = "0" # "1", "2", "3"
# Pick a unique port per process
os.environ["TPU_MESH_CONTROLLER_ADDRESS"] = "localhost:8476"
os.environ["TPU_MESH_CONTROLLER_PORT"] = "8476"
@JosephCatrambone
JosephCatrambone / lib.rs
Last active March 8, 2024 01:32
Embedding GPT-2 in Godot via Rust
mod ml_thread;
use gdnative::prelude::{godot_print, methods, Method, NativeClass, Node as GDNode, InitHandle, godot_init};
use ml_thread::start_language_model_thread;
use std::sync::mpsc::{channel, Receiver, RecvError, Sender, SendError};
const MAX_INPUT_LENGTH: usize = 512;
const BATCH_SIZE: usize = 1;
@ToluClassics
ToluClassics / knn_elasticsearch.py
Last active February 17, 2023 08:47
KNN Nearest Neighbour Search in ElasticSearch
import os
import json
from tqdm import tqdm
import torch
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModel
from elasticsearch import Elasticsearch
class JsonlCollectionIterator:
"""
Download the latest wiki dump files for a language,
If from_date is passed, the latest before that date is downloaded
"""
import requests
from datetime import datetime
from datetime import timedelta
from string import Template
from tqdm import tqdm
@mattiasarro
mattiasarro / rwkv.py
Last active May 27, 2024 09:17
RWKV MVP
# Taken from https://johanwind.github.io/2023/03/23/rwkv_details.html.
# I've added additional comments restructured it a tiny bit, which makes it clearer for me.
import numpy as np
from torch import load as torch_load # Only for loading the model weights
from tokenizers import Tokenizer
exp = np.exp
layer_norm = lambda x, w, b : (x - np.mean(x)) / np.std(x) * w + b
sigmoid = lambda x : 1/(1 + exp(-x))