Skip to content

Instantly share code, notes, and snippets.

View wajihullahbaig's full-sized avatar

wajihullahbaig

  • Islamabad, Pakistan
View GitHub Profile
@thomwolf
thomwolf / top-k-top-p.py
Last active January 2, 2024 07:43
Sample the next token from a probability distribution using top-k and/or nucleus (top-p) sampling
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).
Nucleus filtering is described in Holtzman et al. (http://arxiv.org/abs/1904.09751)
"""
assert logits.dim() == 1 # batch size 1 for now - could be updated for more but the code would be less clear
top_k = min(top_k, logits.size(-1)) # Safety check
@alfakini
alfakini / watcher.py
Created October 16, 2018 00:18
Filesystem events monitoring with Python [watcher.py]
import sys
import time
from watchdog.observers import Observer
from .events import ImagesEventHandler
class ImagesWatcher:
def __init__(self, src_path):
self.__src_path = src_path
self.__event_handler = ImagesEventHandler()
@phimachine
phimachine / train_valid_split.py
Last active April 10, 2020 12:29
This is a pytorch generic function that takes a data.Dataset object and splits it to validation and training efficiently.
import np
from torch.utils.data import Dataset
class GenHelper(Dataset):
def __init__(self, mother, length, mapping):
# here is a mapping from this index to the mother ds index
self.mapping=mapping
self.length=length
self.mother=mother
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#define X_FIELDS \
X(char *, field1) \
X(char *, field2) \
X(char *, field3) \
X(char *, field4) \
@SunnyRaj
SunnyRaj / configure_muliple_gcc.sh
Last active October 10, 2023 09:17
Configure multiple GCC versions on ubuntu
#!/usr/bin/env bash
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt update
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
sudo apt-get install -y gcc-4.8 g++-4.8 gcc-4.9 g++-4.9 gcc-5 g++-5 gcc-6 g++-6 gcc-7 g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10