Skip to content

Instantly share code, notes, and snippets.

View reyoung's full-sized avatar

Yang Yu reyoung

  • Tencent
  • Beijing
View GitHub Profile
@reyoung
reyoung / benchmark_kv_cache_copy.py
Created September 25, 2024 10:58
benchmark_kv_cache_swapping
import argparse
import json
import time
import torch
def benchmark_with_warmups(fn, n_warmup: int, n_iter: int) -> float:
for _ in range(n_warmup):
fn()
from itertools import chain
from typing import Optional, Tuple
from torch.utils.data import DataLoader
from transformers import GPT2Tokenizer, GPT2LMHeadModel, GPT2Model, default_data_collator
from transformers.models.gpt2.modeling_gpt2 import GPT2Block
import datasets
from torch import nn
import torch.nn.functional as F
import torch
#include "a.h"
#include <iostream>
static int _inited = []() -> int {
std::cout << "NS: " << NSFoo() << ", Static: " << StaticFoo()
<< ", Inline: " << InlineFoo() << ", Cls: " << Foo::ClsFoo()
<< ", Weak: " << WeakSymbFoo() << std::endl;
return 0;
}();⏎
@reyoung
reyoung / main.cpp
Last active February 3, 2020 02:05
simple_thread_worker
#include "async_thread_pool.h"
#include <iostream>
int main() {
TimedThreadWorker worker(std::chrono::milliseconds(1));
worker.start();
std::this_thread::sleep_for(std::chrono::seconds(1));
worker.enqueue(std::chrono::milliseconds(100),
[] { std::cout << "hello" << std::endl; });
auto fut = worker.enqueue(std::chrono::milliseconds(350),
[] { std::cout << "!" << std::endl; });
graph G {
A -- B
A -- C
A -- D
}
#include <iostream>
void PrintRow(size_t N, size_t start, size_t i);
void CyclePrint(size_t N, size_t start=1) {
if (N <= 0) {
return;
}
for (size_t i=0;i<N; ++i) {
PrintRow(N, start, i);
#!/bin/bash
BEGIN_PR_ID=11635
END_PR_ID=13159
GH_API_TOKEN=REPLACE_TO_YOUR_API_TOKEN
for ((i=$BEGIN_PR_ID; i<END_PR_ID;++i))
do
curl -H "Authorization: token $GH_API_TOKEN" https://api.github.com/repos/PaddlePaddle/Paddle/pulls/$i > PR.json
merge_sha1=$(cat PR.json | jq -re .merge_commit_sha)
if [[ $? -eq 1 ]]
then
@reyoung
reyoung / benchmark.cc
Created July 5, 2018 09:45
BenchmarkThreadPool
#include "ThreadPool.h"
#include <chrono>
#include <iostream>
#include <thread>
#include <vector>
template <size_t HeavySize> class HeavyObject {
public:
HeavyObject() { vec_.resize(HeavySize); }
#include "c_api_debugger.h"
#include <iostream>
#include <stdint.h>
namespace paddle {
namespace capi {
namespace debugger {
static void PrintArg(std::ostream &os, paddle_arguments arg, uint64_t id,
bool only_shape, size_t seq_level);