Skip to content

Instantly share code, notes, and snippets.

@victoroliv2
victoroliv2 / pytorch_fmha_nested_tensor.py
Created March 21, 2024 01:58
pytorch_fmha_nested_tensor.py
import torch
BATCH = 4
EMB_DIM = 256
HEADS = 8
Q_TOKENS = 512
KV_TOKENS = 16384
q_proj = torch.nested.nested_tensor([torch.zeros(HEADS, Q_TOKENS // (i+1), EMB_DIM) for i in range(BATCH)], dtype=torch.half, device="cuda")
k_proj = torch.nested.nested_tensor([torch.zeros(HEADS, KV_TOKENS // (i+1), EMB_DIM) for i in range(BATCH)], dtype=torch.half, device="cuda")
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#include <Servo.h>
#define MAX_SIGNAL 2000
#define MIN_SIGNAL 700
#define MOTOR_PIN 9
Servo motor;
unsigned long time;
@victoroliv2
victoroliv2 / cross-site-xmlhttprequest.py
Created October 7, 2011 19:09
web.py server which allow cross-site xmlhttprequest
import web
urls = (
'/(.*)', 'Service'
)
app = web.application(urls, globals())
class Service:
def GET(self, name):
web.header('Access-Control-Allow-Origin', '*')
@victoroliv2
victoroliv2 / bc_kernel.c
Created August 8, 2011 13:30
bc_kernel
const char* kernel_source[] =
{
"sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | \n",
" CLK_ADDRESS_NONE | \n",
" CLK_FILTER_NEAREST; \n",
"__kernel void kernel_bc(__read_only image2d_t in, \n",
" __write_only image2d_t out, \n",
" float brightness, \n",
" float contrast) \n",
"{ \n",