Diffusers documentation

Rehberler

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Rehberler

Classifier-free guidance, modelin üretimini prompt ile daha iyi örtüşecek şekilde yönlendirir ve üretim kalitesini, kontrolünü ve prompta uyumunu artırmak için yaygın olarak kullanılır. Farklı yönlendirme yöntemleri türleri vardır ve Diffusers'ta bunlara guiders denir. Bloklar gibi, pipeline'ı yeniden yazmadan farklı kullanım senaryoları için farklı guiders'ları değiştirmek ve kullanmak kolaydır.

Bu kılavuz, guiders arasında geçiş yapmayı, guider parametrelerini ayarlamayı ve onları Hub'a yükleyip paylaşmayı gösterir.

Yönlendiricileri değiştirme

ClassifierFreeGuidance, varsayılan yönlendiricidir ve bir pipeline init_pipeline() ile başlatıldığında oluşturulur. from_config tarafından oluşturulduğundan, modüler bir depodan yüklemeye ihtiyaç duymaz. Bir yönlendirici, modular_model_index.json içinde listelenmez.

Bir guider'ı incelemek için get_component_spec() kullanın.

t2i_pipeline.get_component_spec("guider")
ComponentSpec(name='guider', type_hint=<class 'diffusers.guiders.classifier_free_guidance.ClassifierFreeGuidance'>, description=None, config=FrozenDict([('guidance_scale', 7.5), ('guidance_rescale', 0.0), ('use_original_formulation', False), ('start', 0.0), ('stop', 1.0), ('_use_default_values', ['start', 'guidance_rescale', 'stop', 'use_original_formulation'])]), repo=None, subfolder=None, variant=None, revision=None, default_creation_method='from_config')

Yeni guider'ı update_components() fonksiyonuna geçirerek farklı bir guider'a geçiş yapın.

Giderleri değiştirmek, gider türünü değiştirdiğinizi bildiren bir metin döndürür.

ModularPipeline.update_components: adding guider with new type: PerturbedAttentionGuidance, previous type: ClassifierFreeGuidance
from diffusers import LayerSkipConfig, PerturbedAttentionGuidance

config = LayerSkipConfig(indices=[2, 9], fqn="mid_block.attentions.0.transformer_blocks", skip_attention=False, skip_attention_scores=True, skip_ff=False)
guider = PerturbedAttentionGuidance(
    guidance_scale=5.0, perturbed_guidance_scale=2.5, perturbed_guidance_config=config
)
t2i_pipeline.update_components(guider=guider)

Guider türünün farklı olduğunu doğrulamak için get_component_spec() fonksiyonunu tekrar kullanın.

t2i_pipeline.get_component_spec("guider")
ComponentSpec(name='guider', type_hint=<class 'diffusers.guiders.perturbed_attention_guidance.PerturbedAttentionGuidance'>, description=None, config=FrozenDict([('guidance_scale', 5.0), ('perturbed_guidance_scale', 2.5), ('perturbed_guidance_start', 0.01), ('perturbed_guidance_stop', 0.2), ('perturbed_guidance_layers', None), ('perturbed_guidance_config', LayerSkipConfig(indices=[2, 9], fqn='mid_block.attentions.0.transformer_blocks', skip_attention=False, skip_attention_scores=True, skip_ff=False, dropout=1.0)), ('guidance_rescale', 0.0), ('use_original_formulation', False), ('start', 0.0), ('stop', 1.0), ('_use_default_values', ['perturbed_guidance_start', 'use_original_formulation', 'perturbed_guidance_layers', 'stop', 'start', 'guidance_rescale', 'perturbed_guidance_stop']), ('_class_name', 'PerturbedAttentionGuidance'), ('_diffusers_version', '0.35.0.dev0')]), repo=None, subfolder=None, variant=None, revision=None, default_creation_method='from_config')

Özel yönlendiricileri yükleme

Hub üzerinde modular_model_index.json dosyasıyla zaten kaydedilmiş olan guider'lar artık bir from_config bileşeni yerine bir from_pretrained bileşeni olarak kabul edilir.

{
  "guider": [
    null,
    null,
    {
      "repo": "YiYiXu/modular-loader-t2i-guider",
      "revision": null,
      "subfolder": "pag_guider",
      "type_hint": [
        "diffusers",
        "PerturbedAttentionGuidance"
      ],
      "variant": null
    }
  ]
}

Guider, modular_model_index.json içindeki yükleme spesifikasyonuna göre load_components() çağrıldıktan sonra oluşturulur.

t2i_pipeline = t2i_blocks.init_pipeline("YiYiXu/modular-doc-guider")
# not created during init
assert t2i_pipeline.guider is None
t2i_pipeline.load_components()
# loaded as PAG guider
t2i_pipeline.guider

Guider parametrelerini değiştirme

Guider parametreleri create() yöntemi ve update_components() ile ayarlanabilir. Aşağıdaki örnek guidance_scale değerini değiştirir.

guider_spec = t2i_pipeline.get_component_spec("guider")
guider = guider_spec.create(guidance_scale=10)
t2i_pipeline.update_components(guider=guider)

Özel yönlendiricileri yükleme

Bir özel guider üzerinde push_to_hub() metodunu çağırarak onu Hub'da paylaşın.

guider.push_to_hub("YiYiXu/modular-loader-t2i-guider", subfolder="pag_guider")

Bu guider'ın pipeline tarafından kullanılabilir hale getirilmesi için modular_model_index.json dosyasını düzenleyin veya update_components() yöntemini kullanın.

modular_model_index.json
update_components

modular_model_index.json dosyasını düzenleyin ve guider için bir yükleme spesifikasyonu ekleyin; bunun için guider yapılandırmasını içeren bir klasöre işaret edin.

{
  "guider": [
    "diffusers",
    "PerturbedAttentionGuidance",
    {
      "repo": "YiYiXu/modular-loader-t2i-guider",
      "revision": null,
      "subfolder": "pag_guider",
      "type_hint": [
        "diffusers",
        "PerturbedAttentionGuidance"
      ],
      "variant": null
    }
  ],
Update on GitHub