Skip to content

Instantly share code, notes, and snippets.

View devymex's full-sized avatar

Devymex devymex

View GitHub Profile
@devymex
devymex / saver_llama2_hf.py
Last active November 14, 2023 09:56
Plugin of Megatron-LM for saving llama-2 checkpoint as HuggingFace format
import os, torch, torch.multiprocessing as mp
from transformers import AutoModelForCausalLM, LlamaConfig
CHECK_EQUAL_WITH_HF = '' # A pretrain directory eg. '/data/models/llama-2-hf/7b-chat'
def add_arguments(parser):
group = parser.add_argument_group(title='Llama-2 HF saver.')
group.add_argument('--megatron-path', type=str, default=None,
help='Base directory of megatron checkpoint')
@devymex
devymex / make_files_identical.cpp
Created March 16, 2023 06:41
Compares two files to find differences, then fixes the second file to be identical with the first. Useful when copying a large file between two storage devices.
#include <algorithm>
#include <cstring>
#include <fstream>
#include <iostream>
template<typename _Stream>
size_t GetFileSize(_Stream &stream) {
auto nCurPos = stream.tellg();
stream.seekg(0, std::ios::end);
auto nFileSize = stream.tellg();
#! /bin/bash -e
export TOOLCHAIN_ROOT="/heop/.tool/toolchain/arm-ca9-linux-gnueabihf-6.5"
export PATH=$TOOLCHAIN_ROOT/bin:$PATH
export CPPFLAGS="--sysroot=$TOOLCHAIN_ROOT/arm-ca9-linux-gnueabihf/sysroot"
export AR=arm-linux-ar
export AS=arm-linux-as
export LD=arm-linux-ld
export RANLIB=arm-linux-ranlib
export CC=arm-linux-gcc
#!/bin/bash -e
export TOOLCHAIN_ROOT=/heop/.tool/toolchain/arm-ca9-linux-gnueabihf-6.5
export SYSROOT=$TOOLCHAIN_ROOT/arm-ca9-linux-gnueabihf/sysroot
export CC=$TOOLCHAIN_ROOT/bin/arm-linux-gcc
export CXX=$TOOLCHAIN_ROOT/bin/arm-linux-g++
export AR=$TOOLCHAIN_ROOT/bin/arm-linux-ar
export RANLIB=$TOOLCHAIN_ROOT/bin/arm-linux-ranlib
mkdir -p build
@devymex
devymex / docker_cheetsheet.txt
Last active December 31, 2022 13:00
Docker Cheetsheet
下载镜像:
docker pull <IMAGE_NAME> # https://hub.docker.com/r/nvidia/cuda
列出所有镜像
docker images
运行镜像(运行为一个容器)
@devymex
devymex / nvencoder.cpp
Created May 22, 2022 07:35
Video encoder with GPU
#include "NvEncoder/NvEncoderCuda.h"
#include "NvEncoder/NvEncoderCLIOptions.h"
#include "NvEncoder/NvCodecUtils.h"
#include <cuda_runtime.h>
extern "C" {
#include <libavutil/opt.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
@devymex
devymex / ctimer.hpp
Created April 1, 2022 16:50
high precision timer
/**
* Copyright (C) DeepGlint, Inc - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
*
* CTimer for Code Profile
*
* Written by Devymex <yumengwang@deepglint.com>, Jan. 2019
*/
@devymex
devymex / vswt_onnx_trt7.py
Created February 27, 2022 07:57
Exporting Video-Swin-Transformer to onnx for TensorRT 7.x
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.checkpoint as checkpoint
import numpy as np
import math
def drop_path(x, drop_prob: float = 0., training: bool = False, scale_by_keep: bool = True):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
This is the same as the DropConnect impl I created for EfficientNet, etc networks, however,
@devymex
devymex / run_devbase.sh
Last active June 15, 2021 03:06
Run an docker image as a container with public ssh port
#!/bin/bash -e
if [ $# -eq 0 ]; then
echo "Please specify an name for the new container!"
exit
fi
indices=""
for cid in $(docker container ls -a | sed 1,1d | awk '{print $1}'); do
port=$(docker inspect --format='{{if .NetworkSettings.Ports}}{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostPort}}{{else}}{{"null"}}{{end}}' $cid)
indices=$indices" "$port
@devymex
devymex / Dockerfile
Last active May 31, 2021 06:23
my dockerfile: nvidia/cuda:11.3.0-cudnn8-devel-ubuntu18.04
FROM nvidia/cuda:11.3.0-cudnn8-devel-ubuntu18.04
RUN mkdir -p /home/root
RUN apt update
RUN apt upgrade -y
RUN apt install -y apt-utils dialog
RUN apt install -y bash-completion locate vim tmux unzip htop
RUN apt install -y openssh-server # net-tools iputils-ping curl
RUN apt install -y build-essential pkg-config gdb git
RUN apt install -y libssl-dev libgoogle-glog-dev libgflags-dev