Saturday, October 25, 2025

Sampler - Stable Diffusion

What are Diffusion Models? - Lil'Log (Lilian Weng)

The Illustrated Stable Diffusion - Jay Alammar

  1. DDPM: Denoising Diffusion Probabilistic Model
    1. basic sampler -> Stable Diffusion's basic sampler 
    2. 1000 steps 
  2. DDIM: Denoising Diffusion Implicit Model
    1. DDPM -> DDIM 
    2. 10 ~ 50 steps 
  3. Euler Discrete
    1. Ordinary Differential Equation (OED) 
    2. simple & fast 
    3. same of DDIM or more steps
  4. OLSS: Optimal Linear Subspace Search
    1. fast, but using the old model 
    2. 5 ~ 10 steps 
  5. CM: Consistency Model
    1. 1 step
    2. pixel space
    3. complex calculation
    4. limited high resolution image 
  6. LCM: Latent Consistency Model
    1. 1 ~ 4 steps 
    2. latent space
    3. low dimension calculation
    4. support high resolution image 
    5. need LoRA or need re-training model (cannot use old model) 

Saturday, January 18, 2025

LVM - DDPM, DDIM

  1. Evaluation
    1. Inception Score
    2. FID (Freche Inception Distance)
  2. LVM - Large Visual Model
    1. GAN
    2. DDPM: denoising diffusion probabilistic models (https://arxiv.org/abs/2006.11239)
    3. DDIM: denoising diffusion models (https://arxiv.org/abs/2010.02502)



Thursday, October 10, 2024

PyTorch - get the total number of model parameter

Total number of model parameters


1. simple version

pytorch_total_params = sum(p.numel() for p in model.parameters())

2. listed version

def count_parameters(model):

  str_name = "name"

  str_parameter = "parameter"

  print(f"{str_name:50s}: {str_parameter:10s}")

  total_params = 0

  for name, parameter in model.named_parameters():

    if not parameter.requires_grad:

      continue

    params = parameter.numel()

    print(f"{name:50s}: {params:10s}")

    total_params += params

  print(f"Total Trainable Params: {total_params}")

  return total_params

Sunday, July 14, 2024

how to convert array to vector in c++ fast way

array to vector

#include <vector>

constexpr int vec_size = 5;

float a[vec_size] = {0, 1, 2, 3, 4};

std::vector<float> vec_a(a, a + vec_size); // good


  1. https://sites.google.com/site/hashemian/home/tips-and-tricks/copy-array-cpp
  2. https://stackoverflow.com/questions/8777603/what-is-the-simplest-way-to-convert-array-to-vector
  3. https://www.freecodecamp.org/news/cpp-vector-how-to-initialize-a-vector-in-a-constructor/ <- how to initialize a vector from an array in C++

And vector to array

#include <vector>

constexpr int vec_size = 5;

float a[vec_size] = {0, 1, 2, 3, 4};

std::vector<float> vec_a(a, a + vec_size); // good


#include <algorithm>

float b[vec_size] = {}

std::copy(vec_a.begin(), vec_a.end(), b); // good

  1. https://stackoverflow.com/questions/2923272/how-to-convert-vector-to-array
  2. https://iq.opengenus.org/convert-vector-to-array-in-cpp/

Thursday, July 4, 2024

Python float to hexadecimal & hexadecimal to float, and default flaot vs. fp32

 import struct

def float_to_hex(f):

    return hex(struct.unpack('<I', struct.pack('<f', f))[0])


def hex_to_float(h):

    return struct.unpack('!f', bytes.fromhex(h))[0]


hex_val = "0xbf557ca4"

float_val = hex_to_float(hex_val.replace("0x", ""))

print(f"-0.8339 -> 0xbf557ca4 -> {float_val} <- -0.8339331150054932")

----

-0.8339 -> 0xbf557ca4 -> -0.8339331150054932 <- -0.8339331150054932


import numpy as np

fp32_value = np.float32(-0.8339)

print(f"-0.8339 -> fp32: {fp32_value}")

----

output: -0.8339 -> fp32: -0.833899974822998


fp64_value = -0.8339

print(f"-0.8339 -> fp64: {fp64_value}")

----

output: -0.8339 -> fp64: -0.8339

Sunday, June 23, 2024

About LoRA

LoRA (Low-Rank Adaptation)

- Paper

[Current]


[Before]

  • Measuring the Intrinsic Dimension of Objective Landscapes, 2018
  • Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning, 2020 
[After]
Towards A Unified View of Parameter-Efficient Transfer Learning, 2022

---- 


- YouTube

 https://www.youtube.com/watch?v=dA-NhCtrrVE

 https://www.youtube.com/watch?v=BJqwmDpa0wM


https://www.youtube.com/watch?v=t509sv5MT0w

----

The case for 4-bit precision: k-bit Interence Scaling Laws

Parameter-Efficient Transfer Learning for NLP

Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning

QLoRA: Efficient Finetuning of Quantized LLMs


https://www.youtube.com/watch?v=X4VvO3G6_vw

----

Intrinsic Dimensionality Ezplanins the Effectiveness of Language Model Fine-Tuning




Friday, April 26, 2024

Tuesday, September 26, 2023

Saturday, July 15, 2023

SIMD - transpose

 Intel SIMD (AVX) transpose intrinsics


Intel® Intrinsics Guide

- _shuffle_* (mask)

- permute (mask)

- _unpacklo_, _unpackhi_

- _MM_TRANSPOSE4_PS & c++ - Fastest way to transpose 4x4 byte matrix - Stack Overflow


Example

https://godbolt.org/z/xzfPqnrdo