Skip to content

Commit 4684ea2

Browse files
authored
[docs] #Copied from mechanism (huggingface#6007)
* copied from section * feedback
1 parent b64f835 commit 4684ea2

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

docs/source/en/conceptual/contribution.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,37 @@ if you don't know yet what specific component you would like to add:
297297
- [Model or pipeline](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+pipeline%2Fmodel%22)
298298
- [Scheduler](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+scheduler%22)
299299

300-
Before adding any of the three components, it is strongly recommended that you give the [Philosophy guide](philosophy) a read to better understand the design of any of the three components. Please be aware that
301-
we cannot merge model, scheduler, or pipeline additions that strongly diverge from our design philosophy
302-
as it will lead to API inconsistencies. If you fundamentally disagree with a design choice, please
303-
open a [Feedback issue](https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feedback.md&title=) instead so that it can be discussed whether a certain design
304-
pattern/design choice shall be changed everywhere in the library and whether we shall update our design philosophy. Consistency across the library is very important for us.
300+
Before adding any of the three components, it is strongly recommended that you give the [Philosophy guide](philosophy) a read to better understand the design of any of the three components. Please be aware that we cannot merge model, scheduler, or pipeline additions that strongly diverge from our design philosophy
301+
as it will lead to API inconsistencies. If you fundamentally disagree with a design choice, please open a [Feedback issue](https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feedback.md&title=) instead so that it can be discussed whether a certain design pattern/design choice shall be changed everywhere in the library and whether we shall update our design philosophy. Consistency across the library is very important for us.
305302

306-
Please make sure to add links to the original codebase/paper to the PR and ideally also ping the
307-
original author directly on the PR so that they can follow the progress and potentially help with questions.
303+
Please make sure to add links to the original codebase/paper to the PR and ideally also ping the original author directly on the PR so that they can follow the progress and potentially help with questions.
308304

309305
If you are unsure or stuck in the PR, don't hesitate to leave a message to ask for a first review or help.
310306

307+
#### Copied from mechanism
308+
309+
A unique and important feature to understand when adding any pipeline, model or scheduler code is the `# Copied from` mechanism. You'll see this all over the Diffusers codebase, and the reason we use it is to keep the codebase easy to understand and maintain. Marking code with the `# Copied from` mechanism forces the marked code to be identical to the code it was copied from. This makes it easy to update and propagate changes across many files whenever you run `make fix-copies`.
310+
311+
For example, in the code example below, [`~diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput`] is the original code and `AltDiffusionPipelineOutput` uses the `# Copied from` mechanism to copy it. The only difference is changing the class prefix from `Stable` to `Alt`.
312+
313+
```py
314+
# Copied from diffusers.pipelines.stable_diffusion.pipeline_output.StableDiffusionPipelineOutput with Stable->Alt
315+
class AltDiffusionPipelineOutput(BaseOutput):
316+
"""
317+
Output class for Alt Diffusion pipelines.
318+
319+
Args:
320+
images (`List[PIL.Image.Image]` or `np.ndarray`)
321+
List of denoised PIL images of length `batch_size` or NumPy array of shape `(batch_size, height, width,
322+
num_channels)`.
323+
nsfw_content_detected (`List[bool]`)
324+
List indicating whether the corresponding generated image contains "not-safe-for-work" (nsfw) content or
325+
`None` if safety checking could not be performed.
326+
"""
327+
```
328+
329+
To learn more, read this section of the [~Don't~ Repeat Yourself*](https://huggingface.co/blog/transformers-design-philosophy#4-machine-learning-models-are-static) blog post.
330+
311331
## How to write a good issue
312332

313333
**The better your issue is written, the higher the chances that it will be quickly resolved.**

0 commit comments

Comments
 (0)