작업 기록

StreamDiffusion Conda 설치 과정 기록

스튜디오 오버그래픽스 2025. 10. 26. 00:41

환경 : 윈도우11 / RTX3070 / StreamDiffusion / miniconda

 

#git 설치
https://git-scm.com/download/win

# conda 가상환경 생성 및 실행
conda create -n streamdiffusion python=3.10 -y
conda activate streamdiffusion

# PyTorch 설치
pip install torch==2.1.0 torchvision==0.16.0 --index-url https://download.pytorch.org/whl/cu121

# numpy 다운그레이드
pip install numpy==1.24.3 --force-reinstall

# pillow다운그레이드
pip install pillow==10.1.0 --force-reinstall

# xformers 설치
pip install xformers==0.0.23 --no-deps

# ML 라이브러리 설치
pip install diffusers==0.25.0 transformers==4.36.2 accelerate==0.25.0

# StreamDiffusion 설치
pip install git+https://github.com/cumulo-autumn/StreamDiffusion.git@main#egg=streamdiffusion[tensorrt]

# huggingface_hub를 호환되는 버전으로 다운그레이드
pip install huggingface_hub==0.20.3 --force-reinstall

# TensorRT 설치
python -m streamdiffusion.tools.install-tensorrt

# pywin32
pip install --force-reinstall pywin32

# 최종 확인
pip check

 

import torch
from diffusers import StableDiffusionPipeline, AutoencoderTiny
from streamdiffusion import StreamDiffusion
from streamdiffusion.image_utils import postprocess_image
from PIL import Image

print("이미지 생성 테스트...")

# 모델 로드
pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    torch_dtype=torch.float16
).to("cuda")

# StreamDiffusion 설정
stream = StreamDiffusion(
    pipe,
    t_index_list=[0, 16, 32, 45],
    torch_dtype=torch.float16,
    cfg_type="none",
)

# LCM LoRA 로드 (빠른 생성을 위해)
stream.load_lcm_lora()
stream.fuse_lora()

# Tiny VAE로 가속 (선택사항)
stream.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd").to(
    device=pipe.device, dtype=pipe.dtype
)

# xformers 가속 활성화
pipe.enable_xformers_memory_efficient_attention()

# 프롬프트 설정
prompt = "a beautiful landscape with mountains and a lake, sunset, highly detailed"
stream.prepare(prompt)

# Warmup (처음 몇 번은 느림)
print("Warmup 중...")
for _ in range(4):
    stream.txt2img()

# 이미지 생성
print("이미지 생성 중...")
output = stream.txt2img()
image = postprocess_image(output, output_type="pil")[0]

# 저장
image.save("test_output.png")
print("✓ 이미지 생성 완료! test_output.png 저장됨")

StreamDiffusion으로 이미지 1장 생성 테스트하는 테스트 python 코드