MCPcopy Create free account
hub / github.com/Monalissaa/DisenDiff / CustomDiffusionPipeline

Class CustomDiffusionPipeline

src/diffusers_model_pipeline.py:365–498  ·  view source on GitHub ↗

r""" Pipeline for custom diffusion model. This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.). Args: vae

Source from the content-addressed store, hash-verified

363
364
365class CustomDiffusionPipeline(StableDiffusionPipeline):
366 r"""
367 Pipeline for custom diffusion model.
368
369 This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
370 library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.).
371
372 Args:
373 vae ([`AutoencoderKL`]):
374 Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
375 text_encoder ([`CLIPTextModel`]):
376 Frozen text-encoder. Stable Diffusion uses the text portion of
377 [CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel), specifically
378 the [clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14) variant.
379 tokenizer (`CLIPTokenizer`):
380 Tokenizer of class
381 [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer).
382 unet ([`UNet2DConditionModel`]): Conditional U-Net architecture to denoise the encoded image latents.
383 scheduler ([`SchedulerMixin`]):
384 A scheduler to be used in combination with `unet` to denoise the encoded image latents.
385 safety_checker ([`StableDiffusionSafetyChecker`]):
386 Classification module that estimates whether generated images could be considered offensive or harmful.
387 Please, refer to the [model card](https://huggingface.co/runwayml/stable-diffusion-v1-5) for details.
388 feature_extractor ([`CLIPFeatureExtractor`]):
389 Model that extracts features from generated images to be used as inputs for the `safety_checker`.
390 modifier_token: list of new modifier tokens added or to be added to text_encoder
391 modifier_token_id: list of id of new modifier tokens added or to be added to text_encoder
392 """
393 _optional_components = ["safety_checker", "feature_extractor", "modifier_token"]
394
395 def __init__(
396 self,
397 vae: AutoencoderKL,
398 text_encoder: CLIPTextModel,
399 tokenizer: CLIPTokenizer,
400 unet: UNet2DConditionModel,
401 scheduler: SchedulerMixin,
402 safety_checker: StableDiffusionSafetyChecker,
403 feature_extractor: CLIPFeatureExtractor,
404 requires_safety_checker: bool = True,
405 modifier_token: list = [],
406 modifier_token_id: list = [],
407 ):
408 super().__init__(vae,
409 text_encoder,
410 tokenizer,
411 unet,
412 scheduler,
413 safety_checker,
414 feature_extractor,
415 requires_safety_checker)
416
417 # change attn class
418 self.modifier_token = modifier_token
419 self.modifier_token_id = modifier_token_id
420
421 def add_token(self, initializer_token):
422 initializer_token_id = []

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected