Skip to content

Instantly share code, notes, and snippets.

@eavae
eavae / ast_markdown_splitter.py
Last active September 5, 2024 06:56
A Simple AST based Markdown Splitter
import mistletoe
import re
import mistletoe.markdown_renderer
import warnings
from typing import Any, Callable, List, Sequence, TYPE_CHECKING
from mistletoe.span_token import (
SpanToken,
RawText,
)
@eavae
eavae / example_deepspeed_zero_1.py
Created April 22, 2024 12:00
Simple DeepSpeed with Zero-1
import torch
import enum
import deepspeed
import argparse
from torch import nn
from torch.utils.data import Dataset, DataLoader
from torch.multiprocessing import spawn
class BoolOps(enum.Enum):
@eavae
eavae / pytorch_ddp_example.py
Last active April 22, 2024 08:56
A simple example of pytorch DDP.
import os
import torch
import torch.distributed as distributed
import torch.multiprocessing as multiprocessing
import torch.nn as nn
import torch.optim as optim
from torch.nn.parallel import DistributedDataParallel
def example(rank, world_size):
@eavae
eavae / convert_diffusers_lora_to_sd_webui.py
Created August 23, 2023 07:45
A script help you convert diffusers lora to sd webui format
from pathlib import Path
from diffusers import StableDiffusionXLPipeline
import torch
from safetensors.torch import save_file
# text_encoder.text_model.encoder.layers.0.self_attn.k_proj.lora_linear_layer.down.weight
# lora_te_text_model_encoder_layers_0_self_attn_k_proj.lora_down.weight
# 1. text_encoder -> lora_te, text_encoder_2 -> lora_te2
# 2. map
# 3. .weight -> 2 .alpha -> 1 and replace . -> _
@eavae
eavae / search_space.py
Created August 11, 2021 06:18
An idea about collect hyper parameters.
from collections import OrderedDict
import inspect
import typing
class SearchSpacesDict(OrderedDict):
def __setitem__(self, key, value):
super().__setitem__(key, value)
self.move_to_end(key)
@eavae
eavae / tunable.py
Created August 6, 2021 04:05
tunable parameter
from collections import OrderedDict
import inspect
import typing
class SearchSpacesDict(OrderedDict):
def __setitem__(self, key, value):
super().__setitem__(key, value)
self.move_to_end(key)
class Tunable():
/**
* @file build配置
* @author edpx-mobile
*/
var cwd = process.cwd();
var path = require('path');
// 引入 rider 支持
var epr = require('./edp-rider-config');