先自我介紹一下,小編浙江大學畢業(yè),去過華為、字節(jié)跳動等大廠,目前阿里P7
深知大多數(shù)程序員,想要提升技能,往往是自己摸索成長,但自己不成體系的自學效果低效又漫長,而且極易碰到天花板技術停滯不前!
因此收集整理了一份《2024年最新大數(shù)據(jù)全套學習資料》,初衷也很簡單,就是希望能夠幫助到想自學提升又不知道該從何學起的朋友。
既有適合小白學習的零基礎資料,也有適合3年以上經(jīng)驗的小伙伴深入學習提升的進階課程,涵蓋了95%以上大數(shù)據(jù)知識點,真正體系化!
由于文件比較多,這里只是將部分目錄截圖出來,全套包含大廠面經(jīng)、學習筆記、源碼講義、實戰(zhàn)項目、大綱路線、講解視頻,并且后續(xù)會持續(xù)更新
如果你需要這些資料,可以添加V獲?。簐ip204888 (備注大數(shù)據(jù))
正文
也可以使用特定的pipeline
from diffusers import StableDiffusionPipeline
repo_id = “runwayml/stable-diffusion-v1-5”
pipe = StableDiffusionPipeline.from_pretrained(repo_id, use_safetensors=True)
Community pipelines是原始實現(xiàn)不同于DiffusionPipeline,例如StableDiffusionControlNetPipeline.
**1.1 local pipeline**
from diffusers import DiffusionPipeline
repo_id = “./stable-diffusion-v1-5” # local path
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, use_safetensors=True)
from\_pretrained()方法在檢測到本地路徑時不會下載。
**1.2 swap components in a pipeline**
可以使用另一個兼容的組件來自定義任何流程的默認組件。定制非常重要,因為:
1. 更改調(diào)度器對于探索生成速度和質(zhì)量之間的權衡是重要的。
2. 模型的不同組件通常是獨立訓練的,您可以用性能更好的組件替換掉現(xiàn)有組件。
3. 在微調(diào)過程中,通常只有一些組件(如UNet或文本編碼器)進行訓練。
from diffusers import DiffusionPipeline
repo_id = “runwayml/stable-diffusion-v1-5”
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, use_safetensors=True)
stable_diffusion.scheduler.compatibles
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, DPMSolverMultistepScheduler
repo_id = “runwayml/stable-diffusion-v1-5”
scheduler = EulerDiscreteScheduler.from_pretrained(repo_id, subfolder=“scheduler”)
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, scheduler=scheduler, use_safetensors=True)
可以將PNDMScheduler更換為EulerDiscreteScheduler,在回傳到DiffusionPipeline中。
**1.3 safety checker**
safety checker可以根據(jù)已知的NSFW內(nèi)容檢查生成的輸出,?
from diffusers import DiffusionPipeline
repo_id = “runwayml/stable-diffusion-v1-5”
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, safety_checker=None, use_safetensors=True)
**1.4 reuse components across pipelines**
可以在多個pipeline中可以重復使用相同的組件,以避免將權重加載到RAM中2次
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
model_id = “runwayml/stable-diffusion-v1-5”
stable_diffusion_txt2img = StableDiffusionPipeline.from_pretrained(model_id, use_safetensors=True)
components = stable_diffusion_txt2img.components
可以將components傳遞到另一個pipeline中,無需將權重重新加載到RAM中:
stable_diffusion_img2img = StableDiffusionImg2ImgPipeline(**components)
下面的方式更加靈活:
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
model_id = “runwayml/stable-diffusion-v1-5”
stable_diffusion_txt2img = StableDiffusionPipeline.from_pretrained(model_id, use_safetensors=True)
stable_diffusion_img2img = StableDiffusionImg2ImgPipeline(
vae=stable_diffusion_txt2img.vae,
text_encoder=stable_diffusion_txt2img.text_encoder,
tokenizer=stable_diffusion_txt2img.tokenizer,
unet=stable_diffusion_txt2img.unet,
scheduler=stable_diffusion_txt2img.scheduler,
safety_checker=None,
feature_extractor=None,
requires_safety_checker=False,
)
**1.5 checkpoint variants**
以torch.float16保存,節(jié)省一半的內(nèi)存,但是無法訓練,EMA不用于推理,用于微調(diào)模型。
**2. models**
from diffusers import UNet2DConditionModel
repo_id = “runwayml/stable-diffusion-v1-5”
model = UNet2DConditionModel.from_pretrained(repo_id, subfolder=“unet”, use_safetensors=True)
所有的權重都存儲在一個safetensors中, 可以用.from\_single\_file()來加載模型。safetensors安全且加載速度快。
**2.1 load different stable diffusion formats**
.ckpt也可以用from\_single\_file(),但最好轉成hf格式,可以使用diffusers官方提供的服務轉:[https://huggingface.co/spaces/diffusers/sd-to-diffusers]( )
也可以使用腳本轉:[https://github.com/huggingface/diffusers/blob/main/scripts/convert\_original\_stable\_diffusion\_to\_diffusers.py]( )
python …/diffusers/scripts/convert_original_stable_diffusion_to_diffusers.py --checkpoint_path temporalnetv3.ckpt --original_config_file cldm_v15.yaml --dump_path ./ --controlnet
?A1111 Lora文件,diffusers可以使用[load\_lora\_weights()]( )")加載lora模型:
from diffusers import DiffusionPipeline, UniPCMultistepScheduler
import torch
pipeline = DiffusionPipeline.from_pretrained(
“andite/anything-v4.0”, torch_dtype=torch.float16, safety_checker=None
).to(“cuda”)
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config)
uncomment to download the safetensor weights
#!wget https://civitai.com/api/download/models/19998 -O howls_moving_castle.safetensors
pipeline.load_lora_weights(“.”, weight_name=“howls_moving_castle.safetensors”)
prompt = “masterpiece, illustration, ultra-detailed, cityscape, san francisco, golden gate bridge, california, bay area, in the snow, beautiful detailed starry sky”
negative_prompt = “l(fā)owres, cropped, worst quality, low quality, normal quality, artifacts, signature, watermark, username, blurry, more than one bridge, bad architecture”
images = pipeline(
prompt=prompt,
negative_prompt=negative_prompt,
width=512,
height=512,
num_inference_steps=25,
num_images_per_prompt=4,
generator=torch.manual_seed(0),
).images
from diffusers.utils import make_image_grid
make_image_grid(images, 2, 2)
**3.scheduler**
scheduler沒有參數(shù)化或訓練;由配置文件定義。加載scheduler不會消耗大的內(nèi)存,并且相同的配置文件可以用于各種不同的scheduler,比如下面的scheduler均可與StableDiffusionPipline兼容。
Diffusion流程本質(zhì)上是由擴散模型和scheduler組成的集合,它們在一定程度上彼此獨立。這意味著可以替換流程的某些部分,其中最好的例子就是scheduler。擴散模型通常只定義從噪聲到較少噪聲樣本的前向傳遞過程,而調(diào)度器定義了整個去噪過程,包括:
去噪步驟是多少?隨機的還是確定性的?用什么算法找到去噪樣本? 調(diào)度器可以非常復雜,并且經(jīng)常在去噪速度和去噪質(zhì)量之間進行權衡。
from diffusers import StableDiffusionPipeline
from diffusers import (
DDPMScheduler,
DDIMScheduler,
PNDMScheduler,
網(wǎng)上學習資料一大堆,但如果學到的知識不成體系,遇到問題時只是淺嘗輒止,不再深入研究,那么很難做到真正的技術提升。
需要這份系統(tǒng)化的資料的朋友,可以添加V獲?。簐ip204888 (備注大數(shù)據(jù))
一個人可以走的很快,但一群人才能走的更遠!不論你是正從事IT行業(yè)的老鳥或是對IT行業(yè)感興趣的新人,都歡迎加入我們的的圈子(技術交流、學習資源、職場吐槽、大廠內(nèi)推、面試輔導),讓我們一起學習成長!文章來源地址http://www.zghlxwxcb.cn/news/detail-859917.html
知識不成體系,遇到問題時只是淺嘗輒止,不再深入研究,那么很難做到真正的技術提升。**
需要這份系統(tǒng)化的資料的朋友,可以添加V獲?。簐ip204888 (備注大數(shù)據(jù))
[外鏈圖片轉存中…(img-P82PmwJ4-1713279392977)]文章來源:http://www.zghlxwxcb.cn/news/detail-859917.html
一個人可以走的很快,但一群人才能走的更遠!不論你是正從事IT行業(yè)的老鳥或是對IT行業(yè)感興趣的新人,都歡迎加入我們的的圈子(技術交流、學習資源、職場吐槽、大廠內(nèi)推、面試輔導),讓我們一起學習成長!
到了這里,關于diffusers-Load pipelines,models,and schedulers_diffusers 加載safetensors的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!