Buckets:
| # ModularPipelineBlocks | |
| [ModularPipelineBlocks](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks) هو الكتلة الأساسية لبناء [ModularPipeline](/docs/diffusers/main/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline). يحدد المكونات والمدخلات/المخرجات والحسابات التي يجب أن تنفذها الكتلة لخطوة محددة في خط الأنابيب. تتصل [ModularPipelineBlocks](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks) بالكتل الأخرى باستخدام [state](./modular_diffusers_states) لتسهيل البناء المعياري لسير العمل. | |
| لا يمكن تنفيذ [ModularPipelineBlocks](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks) بمفرده. فهو مخطط لما ينبغي أن يقوم به كل خطوة في خط الأنابيب. لتشغيل خط الأنابيب وتنفيذه فعليًا، يجب تحويل [ModularPipelineBlocks](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks) إلى [ModularPipeline](/docs/diffusers/main/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline). | |
| ستوضح لك هذه الدليل كيفية إنشاء [ModularPipelineBlocks](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks). | |
| ## المدخلات والمخرجات | |
| > [!TIP] | |
| > راجع دليل [الحالات](./modular_diffusers_states) إذا لم تكن على دراية بكيفية عمل الحالة في Modular Diffusers. | |
| يتطلب [ModularPipelineBlocks](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks) `inputs` و`intermediate_outputs`. | |
| - `inputs` هي القيم التي يقرأها الكُتلة من [PipelineState](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_states#diffusers.modular_pipelines.PipelineState) لتنفيذ عمليات الحساب الخاصة بها. يمكن أن تكون هذه القيم قيمًا يوفّرها المستخدم (مثل موجه أو صورة) أو قيمًا ينتجها كُتلة سابقة (مثل `image_latents` المُرمّزة). | |
| استخدم `InputParam` لتعريف `inputs`. | |
| ```py | |
| class ImageEncodeStep(ModularPipelineBlocks): | |
| ... | |
| @property | |
| def inputs(self): | |
| return [ | |
| InputParam(name="image", type_hint="PIL.Image", required=True, description="raw input image to process"), | |
| ] | |
| ... | |
| ``` | |
| - `intermediate_outputs` هي قيم جديدة تنشئها وحدة وتُضاف إلى [PipelineState](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_states#diffusers.modular_pipelines.PipelineState). وتكون `intermediate_outputs` متاحة كـ`inputs` للوحدات اللاحقة، أو متاحة كإخراج نهائي من تشغيل خط الأنابيب. | |
| استخدم `OutputParam` لتعريف `intermediate_outputs`. | |
| ```py | |
| class ImageEncodeStep(ModularPipelineBlocks): | |
| ... | |
| @property | |
| def intermediate_outputs(self): | |
| return [ | |
| OutputParam(name="image_latents", description="latents representing the image"), | |
| ] | |
| ... | |
| ``` | |
| تشارك المدخلات والمخرجات الوسيطة البيانات لربط الكتل. وهي متاحة في أي نقطة، مما يتيح لك تتبع تقدم سير العمل. | |
| ## المكوّنات والإعدادات | |
| يتم تحديد المكونات وإعدادات مستوى خط الأنابيب التي يحتاجها الكتل في [ComponentSpec](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec) و [ConfigSpec](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_components#diffusers.ConfigSpec). | |
| - يتضمن [ComponentSpec](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec) المكونات المتوقعة التي يستخدمها الكتل. تحتاج إلى `name` للمكوّن، ومن الأفضل أن يكون لديك `type_hint` يحدد بالضبط ما هو المكوّن. | |
| - يحتوي [ConfigSpec](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_components#diffusers.ConfigSpec) على إعدادات على مستوى خط الأنابيب تتحكم في السلوك عبر جميع الكتل. | |
| ```py | |
| class ImageEncodeStep(ModularPipelineBlocks): | |
| ... | |
| @property | |
| def expected_components(self): | |
| return [ | |
| ComponentSpec(name="vae", type_hint=AutoencoderKL), | |
| ] | |
| @property | |
| def expected_configs(self): | |
| return [ | |
| ConfigSpec("force_zeros_for_empty_prompt", True), | |
| ] | |
| ... | |
| ``` | |
| عند تحويل الكتل إلى خط أنابيب، تصبح المكونات متاحة للكتلة كحجة أولى في `__call__`. | |
| ## منطق الحساب | |
| يُعرَّف الحساب الذي يؤديه الكتل في طريقة `__call__` ويتبع هيكلية محددة. | |
| 1. استرجع [BlockState](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_states#diffusers.modular_pipelines.BlockState) للحصول على عرض محلي لـ `inputs`. | |
| 2. نفّذ منطق الحساب على `inputs`. | |
| 3. حدّث [PipelineState](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_states#diffusers.modular_pipelines.PipelineState) لدفع التغييرات من [BlockState](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_states#diffusers.modular_pipelines.BlockState) المحلي إلى [PipelineState](/docs/diffusers/main/ar/api/modular_diffusers/pipeline_states#diffusers.modular_pipelines.PipelineState) العام. | |
| 4. أعدّ المكونات والحالة التي تصبح متاحةً للكتلة التالية. | |
| ```py | |
| class ImageEncodeStep(ModularPipelineBlocks): | |
| def __call__(self, components, state): | |
| # Get a local view of the state variables this block needs | |
| block_state = self.get_block_state(state) | |
| # Your computation logic here | |
| # block_state contains all your inputs | |
| # Access them like: block_state.image, block_state.processed_image | |
| # Update the pipeline state with your updated block_states | |
| self.set_block_state(state, block_state) | |
| return components, state | |
| ``` | |
| ## جمع كل شيء معًا | |
| إليك الكتلة الكاملة مع جميع الأجزاء مترابطة. | |
| ```py | |
| from diffusers import ComponentSpec, AutoencoderKL | |
| from diffusers.modular_pipelines import InputParam, ModularPipelineBlocks, OutputParam | |
| class ImageEncodeStep(ModularPipelineBlocks): | |
| @property | |
| def description(self): | |
| return "Encode an image into latent space." | |
| @property | |
| def expected_components(self): | |
| return [ | |
| ComponentSpec(name="vae", type_hint=AutoencoderKL), | |
| ] | |
| @property | |
| def inputs(self): | |
| return [ | |
| InputParam(name="image", type_hint="PIL.Image", required=True, description="raw input image to process"), | |
| ] | |
| @property | |
| def intermediate_outputs(self): | |
| return [ | |
| OutputParam(name="image_latents", type_hint="torch.Tensor", description="latents representing the image"), | |
| ] | |
| def __call__(self, components, state): | |
| block_state = self.get_block_state(state) | |
| block_state.image_latents = components.vae.encode(block_state.image) | |
| self.set_block_state(state, block_state) | |
| return components, state | |
| ``` | |
| يحتوي كل كتلة على خاصية `doc` يتم توليدها تلقائيًا من الخصائص التي عرّفتها أعلاه. وهي توفر ملخصًا لوصف الكتلة ومكوّناتها ومدخلاتها ومخرجاتها. | |
| ```py | |
| block = ImageEncoderStep() | |
| print(block.doc) | |
| class ImageEncodeStep | |
| Encode an image into latent space. | |
| Components: | |
| vae (`AutoencoderKL`) | |
| Inputs: | |
| image (`PIL.Image`): | |
| raw input image to process | |
| Outputs: | |
| image_latents (`torch.Tensor`): | |
| latents representing the image | |
| ``` | |
Xet Storage Details
- Size:
- 8.18 kB
- Xet hash:
- d4a7f4fc9f6c19b633a654221e342e1ebbaeb7097852cc943aba06ed2ed0232e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.