This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function pca(X) | |
-- PCA ------------------------------------------------------------------------- | |
-- X is m x n | |
local mean = torch.mean(X, 1) -- 1 x n | |
local m = X:size(1) | |
local Xm = X - torch.ones(m, 1) * mean | |
Xm:div(math.sqrt(m - 1)) | |
local v,s,_ = torch.svd(Xm:t()) | |
s:cmul(s) -- n | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function YUV422toYUV(input, w, h) | |
local yuv_result = torch.ByteTensor(3, h, w) | |
local x = input:view(h, w, 2) | |
yuv_result[1] = x[{{},{},1}] -- copy Y part | |
local u = yuv_result[2] | |
local v = yuv_result[3] | |
local uv = x[{{},{},2}]:reshape(h,w/2,2) | |
local u_ = uv[{{},{},1}] | |
local v_ = uv[{{},{},2}] | |
u:view(h,w/2, 2)[{{},{},1}] = u_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
torch.chunk2() | |
returns a table with nChunk entries, even in the case that the tensor has < nChunk entries in the specified dimension. | |
Behaviour of the originial torch.chunk() function: | |
th> torch.rand(11):chunk(5) | |
{ | |
1 : DoubleTensor - size: 3 | |
2 : DoubleTensor - size: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.DependencyModel; | |
using System; | |
using System.Linq; | |
using System.Runtime.Loader; | |
using System.Reflection; | |
using System.Collections.Generic; | |
namespace ConsoleApp1 | |
{ | |
class Program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adapted from: https://github.com/lucidrains/vit-pytorch/blob/main/vit_pytorch/vit.py | |
import torch | |
import torch.nn.functional as F | |
from torch import nn | |
from torch.utils import checkpoint | |
from einops import rearrange, repeat | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adapted from: https://github.com/lucidrains/vit-pytorch/blob/main/vit_pytorch/vit.py | |
import torch | |
import torch.nn.functional as F | |
from torch import nn | |
from torch.utils import checkpoint | |
from einops import rearrange, repeat | |
import triton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sent to me by tju01, thx | |
# install base tools | |
apt update | |
apt install protobuf-compiler libssl-dev gcc pkg-config g++ make | |
# install rust | |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh | |
source "$HOME/.cargo/env" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional | |
import torch | |
def precompute_freqs_cis( | |
dim: int, end: int, theta: float = 10000.0, scaling_factor: float = 1.0 | |
) -> torch.Tensor: | |
freqs = 1.0 / (theta ** (torch.arange(0, dim, 2).float() / dim)) | |
t = torch.arange(end, device=freqs.device).float() / scaling_factor # type: ignore | |
freqs = torch.outer(t, freqs).float() # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import sys | |
import torch | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
def parse_args() -> argparse.Namespace: | |
parser = argparse.ArgumentParser( | |
description="Push checkpoints in HF transformers format to the Huggingface Hub.", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. | |
If you don't know the answer to a question, please don't share false information." |