Skip to content

Instantly share code, notes, and snippets.

View buttercutter's full-sized avatar

Phung Cheng Fei buttercutter

View GitHub Profile
@buttercutter
buttercutter / walk_jump.py
Last active July 18, 2024 03:24
A simple code for [Protein Discovery with Discrete Walk-Jump Sampling](http://arxiv.org/abs/2306.12360)
# Credit : gpt-4o
# Reference : [Protein Discovery with Discrete Walk-Jump Sampling](http://arxiv.org/abs/2306.12360)
import torch
import torch.nn as nn
import torch.optim as optim
import math
@buttercutter
buttercutter / cnot_ceviche.py
Created July 7, 2024 00:08
Some optimization for CNOT gate circuit
import ceviche
import matplotlib.pyplot as plt
import pandas as pd
from scipy.optimize import minimize
from autograd import grad
import autograd.numpy as anp
USE_ADAM = 0
USE_SCIPY = ~USE_ADAM
@buttercutter
buttercutter / nlhf.py
Last active March 1, 2024 17:08
A simple code for [Nash Learning from Human Feedback](http://arxiv.org/abs/2312.00886)
# [Nash Learning from Human Feedback](http://arxiv.org/abs/2312.00886)
import os
import math
import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader, Dataset
@buttercutter
buttercutter / hqq.py
Created December 31, 2023 10:21
[Half-Quadratic Quantization of Large Machine Learning Models](https://mobiusml.github.io/hqq_blog/)
# Reference: [Half-Quadratic Quantization of Large Machine Learning Models](https://mobiusml.github.io/hqq_blog/)
import numpy as np
# Define the shrinkage function for soft-thresholding
def shrink(x, beta, p):
return np.sign(x) * np.maximum(np.abs(x) - (np.abs(x)**(p-1))/beta, 0)
# Define the quantization and dequantization operators
@buttercutter
buttercutter / mamba.py
Last active May 22, 2024 05:56
Mamba: Linear-Time Sequence Modeling with Selective State Spaces
# [Mamba: Linear-Time Sequence Modeling with Selective State Spaces](https://arxiv.org/abs/2312.00752)
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader, Dataset
from torch.nn import functional as F
from einops import rearrange, repeat
from tqdm import tqdm
@buttercutter
buttercutter / fff.py
Last active November 26, 2023 07:14
A work-in-progress code for [Fast Feedforward Networks](http://arxiv.org/abs/2308.14711)
import torch
from torch import nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
from tqdm import tqdm
# Custom fast linear layer
class FastLinear(nn.Module):
def __init__(self, in_features, out_features):
@buttercutter
buttercutter / orbital_rotation.ipynb
Created July 3, 2023 03:45
Code refactoring / migration for qiskit OO-VQE
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.