ใƒกใ‚คใƒณใ‚ณใƒณใƒ†ใƒณใƒ„ใธใ‚นใ‚ญใƒƒใƒ—
่ฆ‹ๅ‡บใ—็”ปๅƒ

WSL2ใงStable Cascadeใ‚’่ฉฆใ—ใฆใฟใ‚‹

    ใ€Œใ“ใฎ้ฉๆ–ฐ็š„ใชใƒ†ใ‚ญใ‚นใƒˆใ‹ใ‚‰็”ปๅƒใธใฎใƒขใƒ‡ใƒซใฏใ€ๅ“่ณชใ€ๆŸ”่ปŸๆ€งใ€ๅพฎ่ชฟๆ•ดใ€ใŠใ‚ˆใณๅŠน็އๆ€งใฎใŸใ‚ใฎๆ–ฐใ—ใ„ใƒ™ใƒณใƒใƒžใƒผใ‚ฏใ‚’่จญๅฎšใ—ใ€ใƒใƒผใƒ‰ใ‚ฆใ‚งใ‚ขใฎใƒใƒชใ‚ขใ‚’ใ•ใ‚‰ใซๆŽ’้™คใ™ใ‚‹ใ“ใจใซ้‡็‚นใ‚’็ฝฎใ„ใŸใ€่ˆˆๅ‘ณๆทฑใ„3ๆฎต้šŽใฎใ‚ขใƒ—ใƒญใƒผใƒใ‚’ๅฐŽๅ…ฅใ€ใ—ใŸใ‚‰ใ—ใ„Stable Cascadeใ‚’่ฉฆใ—ใฆใฟใพใ™ใ€‚

    ไฝฟ็”จใ™ใ‚‹PCใฏใƒ‰ใ‚นใƒ‘ใƒฉใ•ใ‚“ใฎใ€ŒGALLERIA UL9C-R49ใ€ใ€‚ใ‚นใƒšใƒƒใ‚ฏใฏ
    ใƒปCPU: Intelยฎ Coreโ„ข i9-13900HX Processor
    ใƒปMem: 64 GB
    ใƒปGPU: NVIDIAยฎ GeForce RTXโ„ข 4090 Laptop GPU(16GB)
    ใƒปGPU: NVIDIAยฎ GeForce RTXโ„ข 4090 (24GB)
    ใƒปOS: Ubuntu22.04 on WSL2๏ผˆWindows 11๏ผ‰
    ใงใ™ใ€‚

    1. ๆบ–ๅ‚™

    venv็’ฐๅขƒใ‚’ๆง‹็ฏ‰ใ—ใฆใ€

    python3 -m venv stable-cascade
    cd $_
    source bin/activate

    Hugging FaceใฎREADMEๅ†…ใ€code exampleใซใ‚ใ‚‹ๅ†…ๅฎน๏ผˆstabilityai/stable-cascade๏ผ‰ใซๅพ“ใฃใฆใ€ใƒ‘ใƒƒใ‚ฑใƒผใ‚ธใฎใ‚คใƒณใ‚นใƒˆใƒผใƒซใงใ™ใ€‚

    pip install git+https://github.com/kashif/diffusers.git@wuerstchen-v3

    2. ใ‚ณใƒผใƒ‰

    ๆตใ—่พผใ‚€ใ‚ณใƒผใƒ‰ใฏใ“ใกใ‚‰ใ€‚code exampleใซใ‚ใ‚‹ๅ†…ๅฎนใ‚’ใƒ™ใƒผใ‚นใซใ€็”ปๅƒใ‚’่กจ็คบใ™ใ‚‹ใŸใ‚ใฎใ‚ณใƒผใƒ‰2่กŒใ‚’ๆœ€ๅพŒใซ่ฟฝๅŠ ใ—ใ€ใƒ—ใƒญใƒณใƒ—ใƒˆใฏ cat ใ‚’ Doraemon ใซๅค‰ๆ›ดใ—ใฆใ„ใพใ™ใ€‚
    ๏ผˆๆ“ฌไบบๅŒ–ใ—ใชใใฆใ‚‚ใƒ‰ใƒฉใˆใ‚‚ใ‚“ใฏใƒ‰ใƒฉใˆใ‚‚ใ‚“ใชใ‚ใ‘ใ ใŒใ€ใพใ€ใ„ใ„ใ‹๏ผ‰

    import torch
    from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
    
    device = "cuda"
    num_images_per_prompt = 2
    
    prior = StableCascadePriorPipeline.from_pretrained(
        "stabilityai/stable-cascade-prior",
        torch_dtype=torch.bfloat16
    ).to(device)
    
    decoder = StableCascadeDecoderPipeline.from_pretrained(
        "stabilityai/stable-cascade",
        torch_dtype=torch.float16
    ).to(device)
    
    prompt = "Anthropomorphic Doraemon dressed as a pilot"
    negative_prompt = ""
    
    prior_output = prior(
        prompt=prompt,
        height=1024,
        width=1024,
        negative_prompt=negative_prompt,
        guidance_scale=4.0,
        num_images_per_prompt=num_images_per_prompt,
        num_inference_steps=20
    )
    decoder_output = decoder(
        image_embeddings=prior_output.image_embeddings.half(),
        prompt=prompt,
        negative_prompt=negative_prompt,
        guidance_scale=0.0,
        output_type="pil",
        num_inference_steps=10
    ).images
    
    #Now decoder_output is a list with your PIL images
    
    for image in decoder_output:
        image.show()

    3. ่ฉฆใ—ใฆใฟใ‚‹

    RTX 4090 Laptop GPU(16GB)ใงใ™ใจใ€ใ„ใคใ‚‚่ฆ‹ๆ…ฃใ‚ŒใŸCUDA OOMใงใ™ใ€‚

    torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 768.00 MiB. GPU 0 has a total capacty of 15.99 GiB of which 0 bytes is free. Including non-PyTorch memory, this process has 17179869184.00 GiB memory in use. Of the allocated memory 14.23 GiB is allocated by PyTorch, and 460.74 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

    ใงใฏใ€RTX 4090(24GB)ใง่ฉฆใ—ใพใ—ใ‚‡ใ†ใ€‚ใƒขใƒ‡ใƒซใƒญใƒผใƒ‰ใ‹ใ‚‰็”ปๅƒ็”Ÿๆˆใซ่‡ณใ‚‹GPUใƒชใ‚ฝใƒผใ‚นใฏใ“ใ‚“ใชๆŽจ็งปใงใ™ใ€‚ๆœ€็ต‚็š„ใซใฏ17.1GBไฝฟ็”จใ—ใฆใ„ใพใ™ใ€‚

    ็”ปๅƒ

    ็”Ÿๆˆใซ่ฆใ—ใŸๆ™‚้–“ใฏ prior ใŒ3็ง’ใ€decodeใŒ2็ง’ใ€ใ‚ใ‚ใ›ใฆ5็ง’ใงใ™ใ€‚

    100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 20/20 [00:03<00:00,  5.36it/s]
    100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 10/10 [00:02<00:00,  4.81it/s]

    ใ‚ณใƒผใƒ‰ใ‚’ๆตใ—่พผใ‚“ใง่กจ็คบใ•ใ‚ŒใŸ็”ปๅƒใŒใ“ใกใ‚‰ใ€‚

    ็”ปๅƒ
    decoder_output[0]
    ็”ปๅƒ
    decoder_output[1]

    ใ‹ใฃใ€ใ‹ใ‚ใ„ใ„ใ€‚

    ใพใจใ‚

    VRAMใฏ17.1GBไฝฟ็”จใงใ—ใŸใ€‚VRAM 24GBใฎGPUใ˜ใ‚ƒใชใ„ใจๅŽณใ—ใ„ใงใ™ใญใ€‚
    ็”Ÿๆˆใซ่ฆใ—ใŸๆ™‚้–“ใฏ ใŠใŠใ‚ˆใ5็ง’ใงใ—ใŸใ€‚้€Ÿใ„ใงใ™ใญใ‡ใ€‚

    ใ•ใฆใ€ๅญฆ็ฟ’ใฎใ€Œ่ฉฆใ—ใฆใฟใ‚‹ใ€ใฏๆ™‚้–“ใŒใ‚ใ‚‹ใจใใซใƒปใƒปใƒปใ€‚https://github.com/Stability-AI/StableCascade

    ย 
    ย 

    noguchi-shoji

    ย 
    ย 
    @IPAjp DX Expert Advisor | Ex-@IETF er | CISSP, CCSP, CISA, CISM, CEH Views my own.

    ใ‚ใชใŸใธใฎใŠใ™ใ™ใ‚