Skip to content

Instantly share code, notes, and snippets.

View billhhh's full-sized avatar
:octocat:
Coding

Bill Wang billhhh

:octocat:
Coding
View GitHub Profile
@billhhh
billhhh / grpo_demo.py
Created April 8, 2025 10:02 — forked from willccbb/grpo_demo.py
GRPO Llama-1B
# train_grpo.py
#
# See https://github.com/willccbb/verifiers for ongoing developments
#
import re
import torch
from datasets import load_dataset, Dataset
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import LoraConfig
from trl import GRPOConfig, GRPOTrainer
@billhhh
billhhh / google-api-docs-offline.md
Created June 12, 2024 10:55 — forked from chrisroos/google-api-docs-offline.md
Using wget to create offline copies of Google API docs

I've used this in the past to grab offline copies of some of the Google API docs.

$ wget --no-parent --recursive --page-requisites --html-extension --convert-links "http://code.google.com/apis/gears/"

# --no-parent - Don't fetch anything in the parent directory of the URL specified
# --page-requisites - Download everything required for the page to display correctly
# --recursive - Recursively download (use default depth of 5)
# --html-extension - Add .html to downloaded html files (this isn't necessarily required for the google code example but might be useful on other sites)

--convert-links - Update links in the downloaded document to point to, either the downloaded copy of a file or a full URL

@billhhh
billhhh / sources.list
Created October 11, 2022 05:45 — forked from ishad0w/sources.list
Ubuntu 20.04 LTS (Focal Fossa) -- Full sources.list
deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
@billhhh
billhhh / fork-is-evil-vfork-is-good-afork-would-be-better.md
Created November 11, 2021 08:59 — forked from nicowilliams/fork-is-evil-vfork-is-good-afork-would-be-better.md
fork() is evil; vfork() is goodness; afork() would be better; clone() is stupid

I recently happened upon an implementation of popen() (different API, same idea) using clone(2), and so I opened an issue requesting use of vfork(2) or posix_spawn() for portability. It turns out that on Linux there's an important advantage to using clone(2). I think I should capture the things I wrote there in a better place. A gist, a blog, whatever.

So here goes.

Long ago, I, like many Unix fans, thought that fork(2) and the fork-exec process spawning model were the greatest thing, and the Windows sucked for only having [exec*()](http://pubs.opengroup.org/onlinepubs/9699919

@billhhh
billhhh / github_desktop_ubuntu.sh
Created August 21, 2021 08:15 — forked from berkorbay/github_desktop_ubuntu.md
To install Github Desktop for Ubuntu
#sudo wget https://github.com/shiftkey/desktop/releases/download/release-2.1.0-linux1/GitHubDesktop-linux-2.1.0-linux1.deb
#sudo gdebi GitHubDesktop-linux-2.1.0-linux1.deb
# UPDATE (2021-03-05): Thanks to PaoloRanzi81's comment, the updated code is as follows https://gist.github.com/PaoloRanzi81
sudo wget https://github.com/shiftkey/desktop/releases/download/release-2.6.3-linux1/GitHubDesktop-linux-2.6.3-linux1.deb
### Uncomment below line if you have not installed gdebi-core before
# sudo apt-get install gdebi-core
sudo gdebi GitHubDesktop-linux-2.6.3-linux1.deb
import nibabel as nib
import numpy as np
data = np.ones((32, 32, 15, 100), dtype=np.int16) # dummy data in numpy matrix
img = nib.Nifti1Image(data, np.eye(4)) # Save axis for data (just identity)
img.header.get_xyzt_units()
img.to_filename(os.path.join('build','test4d.nii.gz')) # Save as NiBabel file
@billhhh
billhhh / pagerank.py
Created April 8, 2021 05:30 — forked from diogojc/pagerank.py
python implementation of pagerank
import numpy as np
from scipy.sparse import csc_matrix
def pageRank(G, s = .85, maxerr = .001):
"""
Computes the pagerank for each of the n states.
Used in webpage ranking and text summarization using unweighted
or weighted transitions respectively.
@billhhh
billhhh / contextual_loss.py
Created August 7, 2020 04:32 — forked from yunjey/contextual_loss.py
pytorch implementation of contextual loss: https://arxiv.org/abs/1803.02077
def contextual_loss(x, y, h=0.5):
"""Computes contextual loss between x and y.
Args:
x: features of shape (N, C, H, W).
y: features of shape (N, C, H, W).
Returns:
cx_loss = contextual loss between x and y (Eq (1) in the paper)
"""
@billhhh
billhhh / avl_tree.py
Created July 9, 2020 12:50 — forked from girish3/avl_tree.py
AVL tree implementation in python
#import random, math
outputdebug = False
def debug(msg):
if outputdebug:
print msg
class Node():
def __init__(self, key):
@billhhh
billhhh / download_olivetty_faces.py
Created November 10, 2019 00:03 — forked from mick001/download_olivetty_faces.py
Download Olivetti faces dataset in Python
# Imports
from sklearn.datasets import fetch_olivetti_faces
import numpy as np
# Download Olivetti faces dataset
olivetti = fetch_olivetti_faces()
x = olivetti.images
y = olivetti.target
# Print info on shapes and reshape where necessary