Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Génération automatique de docstrings","local":"auto-generating-docstrings","sections":[{"title":"@auto_docstring","local":"autodocstring","sections":[],"depth":2},{"title":"Utilisation","local":"usage","sections":[{"title":"Classes de modèles","local":"model-classes","sections":[],"depth":3},{"title":"Classes de configuration","local":"config-classes","sections":[],"depth":3},{"title":"Classes de processeur","local":"processor-classes","sections":[{"title":"Processeurs d'images et de vidéos","local":"image-and-video-processors","sections":[],"depth":4}],"depth":3},{"title":"Fonctions","local":"functions","sections":[],"depth":3},{"title":"Documenter les arguments","local":"documenting-arguments","sections":[],"depth":3}],"depth":2},{"title":"Vérification des docstrings","local":"checking-the-docstrings","sections":[],"depth":2},{"title":"Liste de contrôle de référence rapide","local":"quick-reference-checklist","sections":[],"depth":2},{"title":"Fonctionnement","local":"how-it-works","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/transformers/main/en/_app/immutable/entry/start.DYIO-UII.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DSYYoqAA.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/BovLmb3z.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/entry/app.D2_KizbC.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/WyYpyc-L.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DYBfcveH.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DOLBYqcr.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/nodes/0.ByO_lNbj.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/ZtBhN-Ei.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/nodes/11.CgcRyIiP.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/D-dvW--N.js" rel="modulepreload"> | |
| <!--1wlpssc--><meta name="hf:doc:metadata" content="{"title":"Auto-generating docstrings","local":"auto-generating-docstrings","sections":[{"title":"@auto_docstring","local":"autodocstring","sections":[],"depth":2},{"title":"Usage","local":"usage","sections":[{"title":"Model classes","local":"model-classes","sections":[],"depth":3},{"title":"Config classes","local":"config-classes","sections":[],"depth":3},{"title":"Processor classes","local":"processor-classes","sections":[{"title":"Image and video processors","local":"image-and-video-processors","sections":[],"depth":4}],"depth":3},{"title":"Functions","local":"functions","sections":[],"depth":3},{"title":"Documenting arguments","local":"documenting-arguments","sections":[],"depth":3}],"depth":2},{"title":"Checking the docstrings","local":"checking-the-docstrings","sections":[],"depth":2},{"title":"Quick-reference checklist","local":"quick-reference-checklist","sections":[],"depth":2},{"title":"How it works","local":"how-it-works","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/transformers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="auto-generating-docstrings" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#auto-generating-docstrings"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Génération automatique de docstrings<!----></span></h1><!--]--><!----> <p>Le décorateur <code>@auto_docstring</code> génère des docstrings cohérentes pour les classes et méthodes de modèles. Il intègre automatiquement les descriptions standard des arguments, de sorte que vous n’avez à documenter que les arguments nouveaux ou personnalisés. Lors de l’<a href="./modular_transformers">ajout d’un nouveau modèle</a>, évitez les éléments de boilerplate et concentrez-vous sur ce qui est nouveau.</p> <!--[1--><h2 class="relative group"><a id="autodocstring" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#autodocstring"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->@auto_docstring<!----></span></h2><!--]--><!----> <p>Importez le décorateur dans votre fichier <code>modular_model.py</code> (ou <code>modeling_model.py</code> pour les modèles plus anciens).</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> ...utils <span class="hljs-keyword">import</span> auto_docstring<!----></pre></div><!----> <p>Si votre modèle hérite d’un modèle d’une autre bibliothèque dans un fichier modulaire, <code>@auto_docstring</code> est déjà appliqué dans la classe parente. <code>make fix-repo</code> le copie pour vous dans le fichier généré <code>modeling_model.py</code>. N’appliquez le décorateur explicitement que pour personnaliser son comportement (modèles autonomes, intros personnalisés ou arguments surchargés).</p> <blockquote class="warning"><p>Lorsque vous écrasez un décorateur dans un fichier modulaire, incluez <strong>tous</strong> les décorateurs de la fonction ou de la classe parente. Si vous n'en écrasez qu'une partie, les autres n'apparaîtront pas dans le fichier de modélisation généré.</p></blockquote> <p>Le décorateur accepte les arguments facultatifs suivants :</p> <table><thead><tr><th>argument</th><th>description</th></tr></thead><tbody><tr><td><code>custom_intro</code></td><td>Une description de la classe ou de la méthode, insérée avant la section Args. Obligatoire pour les classes qui ne se terminent pas par un <a href="#how-it-works">suffixe reconnu</a> comme <code>ForCausalLM</code> ou <code>ForTokenClassification</code>.</td></tr><tr><td><code>custom_args</code></td><td>Texte de la docstring pour des paramètres spécifiques. Utile lorsque les mêmes arguments personnalisés apparaissent à plusieurs endroits dans le fichier de modélisation.</td></tr><tr><td><code>checkpoint</code></td><td>Identifiant de point de contrôle de modèle (<code>"org/my-model"</code>) utilisé pour générer des exemples d'utilisation. Remplace le point de contrôle inféré automatiquement à partir de la classe de configuration. Défini généralement sur les classes de configuration.</td></tr></tbody></table> <!--[1--><h2 class="relative group"><a id="usage" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#usage"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Utilisation<!----></span></h2><!--]--><!----> <p>Le fonctionnement de <code>@auto_docstring</code> dépend de l'élément décoré. Les classes de modèle récupèrent la documentation des paramètres depuis <code>__init__</code>, les classes de configuration depuis les annotations au niveau de la classe, les classes de processeur génèrent automatiquement des descriptions à partir de leurs composants, et les méthodes comme <code>forward</code> obtiennent les types de retour et des exemples d'utilisation.</p> <!--[2--><h3 class="relative group"><a id="model-classes" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#model-classes"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Classes de modèles<!----></span></h3><!--]--><!----> <p>Placez <code>@auto_docstring</code> directement au-dessus de la définition de la classe. Le décorateur dérive les descriptions des paramètres de la signature et de la docstring de la méthode <code>__init__</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> transformers.modeling_utils <span class="hljs-keyword">import</span> PreTrainedModel | |
| <span class="hljs-keyword">from</span> ...utils <span class="hljs-keyword">import</span> auto_docstring | |
| <span class="hljs-meta">@auto_docstring</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyAwesomeModel</span>(<span class="hljs-title class_ inherited__">PreTrainedModel</span>): | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, config, custom_parameter: <span class="hljs-built_in">int</span> = <span class="hljs-number">10</span>, another_custom_arg: <span class="hljs-built_in">str</span> = <span class="hljs-string">"default"</span></span>): | |
| <span class="hljs-string">r""" | |
| custom_parameter (`int`, *optional*, defaults to 10): | |
| Description of the custom_parameter for MyAwesomeModel. | |
| another_custom_arg (`str`, *optional*, defaults to "default"): | |
| Documentation for another unique argument. | |
| """</span> | |
| <span class="hljs-built_in">super</span>().__init__(config) | |
| <span class="hljs-variable language_">self</span>.custom_parameter = custom_parameter | |
| <span class="hljs-variable language_">self</span>.another_custom_arg = another_custom_arg | |
| <span class="hljs-comment"># ... rest of your init</span> | |
| <span class="hljs-comment"># ... other methods</span><!----></pre></div><!----> <p>Passez <code>custom_intro</code> et <code>custom_args</code> pour un contrôle plus fin. Les arguments personnalisés peuvent être placés dans <code>custom_args</code> ou dans la docstring de <code>__init__</code>. Utilisez <code>custom_args</code> lorsque les mêmes arguments se répètent dans plusieurs méthodes.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-meta">@auto_docstring(<span class="hljs-params"> | |
| custom_intro=<span class="hljs-string">"""This model performs specific synergistic operations. | |
| It builds upon the standard Transformer architecture with unique modifications."""</span>, | |
| custom_args=<span class="hljs-string">""" | |
| custom_parameter (`type`, *optional*, defaults to `default_value`): | |
| A concise description for custom_parameter if not defined or overriding the description in `auto_docstring.py`. | |
| internal_helper_arg (`type`, *optional*, defaults to `default_value`): | |
| A concise description for internal_helper_arg if not defined or overriding the description in `auto_docstring.py`. | |
| """</span> | |
| </span>)</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MySpecialModel</span>(<span class="hljs-title class_ inherited__">PreTrainedModel</span>): | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, config: ConfigType, custom_parameter: <span class="hljs-string">"type"</span> = <span class="hljs-string">"default_value"</span>, internal_helper_arg=<span class="hljs-literal">None</span></span>): | |
| <span class="hljs-comment"># ...</span><!----></pre></div><!----> <p>Appliquez également <code>@auto_docstring</code> aux classes qui héritent de <a href="/docs/transformers/main/fr/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-meta">@auto_docstring(<span class="hljs-params"> | |
| custom_intro=<span class="hljs-string">""" | |
| Custom model outputs with additional fields. | |
| """</span> | |
| </span>)</span> | |
| <span class="hljs-meta">@dataclass</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModelOutput</span>(<span class="hljs-title class_ inherited__">ImageClassifierOutput</span>): | |
| <span class="hljs-string">r""" | |
| loss (`torch.Tensor`, *optional*): | |
| The loss of the model. | |
| custom_field (`torch.Tensor` of shape `(batch_size, hidden_size)`, *optional*): | |
| A custom output field specific to this model. | |
| """</span> | |
| <span class="hljs-comment"># Standard fields (hidden_states, logits, attentions, etc.) are documented automatically when</span> | |
| <span class="hljs-comment"># the description matches the standard text. Loss typically varies per model, so document it above.</span> | |
| loss: <span class="hljs-type">Optional</span>[torch.Tensor] = <span class="hljs-literal">None</span> | |
| logits: <span class="hljs-type">Optional</span>[torch.Tensor] = <span class="hljs-literal">None</span> | |
| hidden_states: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">tuple</span>[torch.Tensor, ...]] = <span class="hljs-literal">None</span> | |
| attentions: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">tuple</span>[torch.Tensor, ...]] = <span class="hljs-literal">None</span> | |
| <span class="hljs-comment"># Custom fields need to be documented in the docstring above</span> | |
| custom_field: <span class="hljs-type">Optional</span>[torch.Tensor] = <span class="hljs-literal">None</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="config-classes" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#config-classes"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Classes de configuration<!----></span></h3><!--]--><!----> <p>Placez <code>@auto_docstring</code> directement au-dessus d'une sous-classe de <a href="/docs/transformers/main/fr/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a>, aux côtés du décorateur <code>@strict</code>. <code>@strict</code> ajoute une validation de types à l'exécution et transforme la classe en dataclass validée. Les paramètres de configuration sont des <em>annotations au niveau de la classe</em> (et non des arguments de <code>__init__</code>), et <code>@auto_docstring</code> les lit depuis le corps de la classe pour générer la documentation.</p> <p><code>ConfigArgs</code> fournit des paramètres standard tels que <code>vocab_size</code>, <code>hidden_size</code> et <code>num_hidden_layers</code>, de sorte qu’ils n’ont pas besoin d’être décrits sauf si leur comportement diffère. Les paramètres de base de <a href="/docs/transformers/main/fr/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> sont exclus automatiquement. L’argument <code>checkpoint</code> génère l’exemple d’utilisation.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> huggingface_hub.dataclasses <span class="hljs-keyword">import</span> strict | |
| <span class="hljs-keyword">from</span> ...configuration_utils <span class="hljs-keyword">import</span> PreTrainedConfig | |
| <span class="hljs-keyword">from</span> ...utils <span class="hljs-keyword">import</span> auto_docstring | |
| <span class="hljs-meta">@strict</span> | |
| <span class="hljs-meta">@auto_docstring(<span class="hljs-params">checkpoint=<span class="hljs-string">"org/my-model-checkpoint"</span></span>)</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModelConfig</span>(<span class="hljs-title class_ inherited__">PreTrainedConfig</span>): | |
| <span class="hljs-string">r""" | |
| custom_param (`int`, *optional*, defaults to 64): | |
| Description of a parameter specific to this model. | |
| another_param (`str`, *optional*, defaults to `"gelu"`): | |
| Description of another model-specific parameter. | |
| ```python | |
| from transformers import MyModelConfig, MyModel | |
| configuration = MyModelConfig() | |
| model = MyModel(configuration) | |
| configuration = model.config | |
| ``` | |
| """</span> | |
| model_type = <span class="hljs-string">"my_model"</span> | |
| <span class="hljs-comment"># Standard params (vocab_size, hidden_size, etc.) are auto-documented from ConfigArgs.</span> | |
| vocab_size: <span class="hljs-built_in">int</span> = <span class="hljs-number">32000</span> | |
| hidden_size: <span class="hljs-built_in">int</span> = <span class="hljs-number">768</span> | |
| num_hidden_layers: <span class="hljs-built_in">int</span> = <span class="hljs-number">12</span> | |
| <span class="hljs-comment"># Model-specific params must be documented in the class docstring above.</span> | |
| custom_param: <span class="hljs-built_in">int</span> = <span class="hljs-number">64</span> | |
| another_param: <span class="hljs-built_in">str</span> = <span class="hljs-string">"gelu"</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="processor-classes" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processor-classes"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Classes de processeur<!----></span></h3><!--]--><!----> <p>Les processeurs multimodaux (sous-classes de <a href="/docs/transformers/main/fr/main_classes/processors#transformers.ProcessorMixin">ProcessorMixin</a>, <code>processing_*.py</code>) utilisent toujours le simple <code>@auto_docstring</code>. L'introduction de la classe est générée automatiquement. Documentez uniquement les paramètres de <code>__init__</code> non déjà couverts par <code>ProcessorArgs</code> (<code>image_processor</code>, <code>tokenizer</code>, <code>chat_template</code>, et autres).</p> <p>Si tous les paramètres sont standards, omettez la docstring. Décorez également <code>__call__</code> avec <code>@auto_docstring</code>. La docstring de son corps ne contient qu'une section <code>Returns:</code> ainsi que les arguments d'appel spécifiques au modèle. <code>return_tensors</code> est ajouté automatiquement.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> ...processing_utils <span class="hljs-keyword">import</span> ProcessorMixin, ProcessingKwargs, Unpack | |
| <span class="hljs-keyword">from</span> ...utils <span class="hljs-keyword">import</span> auto_docstring | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModelProcessorKwargs</span>(ProcessingKwargs, total=<span class="hljs-literal">False</span>): | |
| <span class="hljs-string">""" | |
| custom_call_kwarg (`bool`, *optional*, defaults to `False`): | |
| A parameter with a default that can passed to __call__ which is not | |
| covered by the standard processor arguments (including each modality). | |
| """</span> | |
| custom_call_kwarg: <span class="hljs-built_in">bool</span> | |
| <span class="hljs-meta">@auto_docstring</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModelProcessor</span>(<span class="hljs-title class_ inherited__">ProcessorMixin</span>): | |
| valid_processor_kwargs = MyModelProcessorKwargs | |
| custom_call_kwarg = <span class="hljs-literal">False</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, image_processor=<span class="hljs-literal">None</span>, tokenizer=<span class="hljs-literal">None</span>, custom_param: <span class="hljs-built_in">int</span> = <span class="hljs-number">4</span>, **kwargs</span>): | |
| <span class="hljs-string">r""" | |
| custom_param (`int`, *optional*, defaults to 4): | |
| A parameter specific to this processor not covered by the standard ProcessorArgs. | |
| """</span> | |
| <span class="hljs-built_in">super</span>().__init__(image_processor, tokenizer) | |
| <span class="hljs-variable language_">self</span>.custom_param = custom_param | |
| <span class="hljs-meta"> @auto_docstring</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">self, images=<span class="hljs-literal">None</span>, text=<span class="hljs-literal">None</span>, **kwargs: Unpack[MyModelProcessorKwargs]</span>): | |
| <span class="hljs-string">r""" | |
| Returns: | |
| [BatchFeature](/docs/transformers/main/en/main_classes/feature_extractor#transformers.BatchFeature): A [BatchFeature](/docs/transformers/main/en/main_classes/feature_extractor#transformers.BatchFeature) with the following fields: | |
| - **input_ids** -- Token ids to be fed to the model. | |
| - **pixel_values** -- Pixel values to be fed to the model. | |
| """</span> | |
| <span class="hljs-comment"># ...</span><!----></pre></div><!----> <!--[3--><h4 class="relative group"><a id="image-and-video-processors" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#image-and-video-processors"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Processeurs d'images et de vidéos<!----></span></h4><!--]--><!----> <p>Les processeurs d’images et de vidéos (sous-classes de <code>BaseImageProcessor</code>, <code>image_processing_*.py</code>) suivent l’un des deux modèles suivants.</p> <p>Si le processeur possède des paramètres spécifiques au modèle, définissez un TypedDict <code>XxxImageProcessorKwargs(ImagesKwargs, total=False)</code> avec une docstring pour ces paramètres, définissez <code>valid_kwargs</code> sur la classe et utilisez <code>@auto_docstring</code> tel quel. Le <code>__init__</code> n'a pas de docstring.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModelImageProcessorKwargs</span>(ImagesKwargs, total=<span class="hljs-literal">False</span>): | |
| <span class="hljs-string">r""" | |
| custom_threshold (`float`, *optional*, defaults to `self.custom_threshold`): | |
| A parameter specific to this image processor. | |
| """</span> | |
| custom_threshold: <span class="hljs-built_in">float</span> | <span class="hljs-literal">None</span> | |
| <span class="hljs-meta">@auto_docstring</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModelImageProcessor</span>(<span class="hljs-title class_ inherited__">TorchvisionBackend</span>): | |
| valid_kwargs = MyModelImageProcessorKwargs | |
| custom_threshold: <span class="hljs-built_in">float</span> = <span class="hljs-number">0.5</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, **kwargs: Unpack[MyModelImageProcessorKwargs]</span>): | |
| <span class="hljs-built_in">super</span>().__init__(**kwargs)<!----></pre></div><!----> <p>Si la classe ne définit que des attributs de classe standard (<code>size</code>, <code>resample</code>, <code>image_mean</code>, etc.) sans kwargs personnalisés, utilisez <code>@auto_docstring(custom_intro="Constructs a MyModel image processor.")</code> à la place.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-meta">@auto_docstring(<span class="hljs-params">custom_intro=<span class="hljs-string">"Constructs a MyModel image processor."</span></span>)</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModelImageProcessor</span>(<span class="hljs-title class_ inherited__">TorchvisionBackend</span>): | |
| resample = PILImageResampling.BICUBIC | |
| image_mean = IMAGENET_STANDARD_MEAN | |
| image_std = IMAGENET_STANDARD_STD | |
| size = {<span class="hljs-string">"height"</span>: <span class="hljs-number">224</span>, <span class="hljs-string">"width"</span>: <span class="hljs-number">224</span>}<!----></pre></div><!----> <p>Lors de la surcharge de <code>preprocess</code>, décorez-le avec <code>@auto_docstring</code> et documentez uniquement les arguments non présents dans <code>ImageProcessorArgs</code>. Les arguments standard et <code>return_tensors</code> sont inclus automatiquement.</p> <!--[2--><h3 class="relative group"><a id="functions" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#functions"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Fonctions<!----></span></h3><!--]--><!----> <p>Placez <code>@auto_docstring</code> directement au-dessus de la définition de la fonction. Le décorateur dérive les descriptions des paramètres de la signature de la fonction.</p> <p>Le décorateur génère le texte de la valeur de retour à partir de la docstring de la classe <code>ModelOutput</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModel</span>(<span class="hljs-title class_ inherited__">PreTrainedModel</span>): | |
| <span class="hljs-comment"># ...</span> | |
| <span class="hljs-meta"> @auto_docstring</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params"> | |
| self, | |
| input_ids: <span class="hljs-type">Optional</span>[torch.Tensor] = <span class="hljs-literal">None</span>, | |
| attention_mask: <span class="hljs-type">Optional</span>[torch.Tensor] = <span class="hljs-literal">None</span>, | |
| new_custom_argument: <span class="hljs-type">Optional</span>[torch.Tensor] = <span class="hljs-literal">None</span>, | |
| <span class="hljs-comment"># ... other arguments</span> | |
| </span>) -> <span class="hljs-type">Union</span>[<span class="hljs-type">Tuple</span>, ModelOutput]: | |
| <span class="hljs-string">r""" | |
| new_custom_argument (`torch.Tensor`, *optional*): | |
| Description of this new custom argument and its expected shape or type. | |
| """</span> | |
| <span class="hljs-comment"># ...</span><!----></pre></div><!----> <p>Passez <code>custom_intro</code> et <code>custom_args</code> pour un contrôle plus fin. Utilisez <code>custom_args</code> pour définir une fois la documentation des arguments partagés lorsque les mêmes paramètres apparaissent dans plusieurs méthodes.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!---->MODEL_COMMON_CUSTOM_ARGS = <span class="hljs-string">r""" | |
| common_arg_1 (`torch.Tensor`, *optional*, defaults to `default_value`): | |
| Description of common_arg_1 | |
| common_arg_2 (`torch.Tensor`, *optional*, defaults to `default_value`): | |
| Description of common_arg_2 | |
| """</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModel</span>(<span class="hljs-title class_ inherited__">PreTrainedModel</span>): | |
| <span class="hljs-comment"># ...</span> | |
| <span class="hljs-meta"> @auto_docstring(<span class="hljs-params"> | |
| custom_intro=<span class="hljs-string">"""This is a custom introduction for the function."""</span>, | |
| custom_args=MODEL_COMMON_CUSTOM_ARGS | |
| </span>)</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, input_ids=<span class="hljs-literal">None</span>, common_arg_1=<span class="hljs-literal">None</span>, common_arg_2=<span class="hljs-literal">None</span></span>) -> ModelOutput: | |
| <span class="hljs-string">r"""method-specific args go here"""</span> | |
| <span class="hljs-comment"># ...</span><!----></pre></div><!----> <p>Écrivez manuellement les sections <code>Returns</code> et <code>Examples</code> dans la docstring pour remplacer les versions générées automatiquement.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----> <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, input_ids=<span class="hljs-literal">None</span></span>) -> torch.Tensor: | |
| <span class="hljs-string">r""" | |
| Returns: | |
| `torch.Tensor`: A custom Returns section for non-ModelOutput return types. | |
| Example: | |
| ```python | |
| model = MyModel.from_pretrained("org/my-model") | |
| output = model(input_ids) | |
| ``` | |
| """</span> | |
| <span class="hljs-comment"># ...</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="documenting-arguments" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#documenting-arguments"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Documenter les arguments<!----></span></h3><!--]--><!----> <p>Suivez ces règles lors de la documentation des différents types d’arguments.</p> <ul><li><p><code>auto_docstring.py</code> définit les arguments standard (<code>input_ids</code>, <code>attention_mask</code>, <code>pixel_values</code>, etc.) et les inclut automatiquement. Ne les redéfinissez pas localement, sauf si l’argument se comporte différemment dans votre modèle.</p> <p>Si un argument standard se comporte différemment dans votre modèle, définissez-le localement dans un bloc <code>r""" """</code>. La définition locale a la priorité. L’argument <code>labels</code>, par exemple, est souvent personnalisé pour chaque modèle et nécessite fréquemment une surcharge.</p></li> <li><p>Les arguments de configuration standard (<code>vocab_size</code>, <code>hidden_size</code>, <code>num_hidden_layers</code>, etc.) suivent le même principe mais proviennent de <code>ConfigArgs</code>. Les arguments de processeur standard (<code>image_processor</code>, <code>tokenizer</code>, <code>do_resize</code>, <code>return_tensors</code>, etc.) proviennent de <code>ProcessorArgs</code> et <code>ImageProcessorArgs</code>. Ne documentez un paramètre que s'il est spécifique au modèle ou s'il se comporte différemment de la description standard.</p></li> <li><p>Documentez les nouveaux arguments ou les arguments personnalisés dans un bloc <code>r""" """</code>. Placez-les après la signature pour les fonctions, dans la docstring de <code>__init__</code> pour les classes de modèles ou de processeurs, dans la docstring du corps de la classe pour les classes de configuration, ou dans le corps du TypedDict <code>XxxImageProcessorKwargs</code> pour les processeurs d'images.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-py "><!---->argument_name (`<span class="hljs-built_in">type</span>`, *optional*, defaults to `X`): | |
| Description of the argument. | |
| Explain its purpose, expected shape/<span class="hljs-built_in">type</span> <span class="hljs-keyword">if</span> <span class="hljs-built_in">complex</span>, <span class="hljs-keyword">and</span> default behavior. | |
| This can span multiple lines.<!----></pre></div><!----> <ul><li>Incluez <code>type</code> entre guillemets.</li> <li>Ajoutez <em>facultatif</em> si l'argument n'est pas requis ou s'il possède une valeur par défaut.</li> <li>Ajoutez « par défaut X » s’il existe une valeur par défaut. Il n’est pas nécessaire d’ajouter « par défaut <code>None</code> » si la valeur par défaut est <code>None</code>.</li> <li>Passez le même bloc dans <code>custom_args</code> lorsque les mêmes arguments se répètent dans plusieurs méthodes (voir l'<a href="#functions">exemple de fonctions ci-dessus</a>).</li></ul></li> <li><p>Le décorateur extrait automatiquement les types à partir des signatures de fonctions. Si un paramètre possède une annotation de type, il n’est pas nécessaire de répéter le type dans la chaîne de formatage de la docstring. Lorsque les deux sont présents, le type de la signature prévaut. Le type de la docstring sert de repli pour les paramètres non annotés.</p></li></ul> <!--[1--><h2 class="relative group"><a id="checking-the-docstrings" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#checking-the-docstrings"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Vérification des docstrings<!----></span></h2><!--]--><!----> <p>Un script utilitaire valide les docstrings lorsque vous ouvrez une pull request. La CI exécute le script et vérifie les éléments suivants.</p> <blockquote class="tip"><p>Si vous voyez un <code>[ERROR]</code> dans la sortie, ajoutez la description du paramètre à la docstring ou à la classe Args appropriée dans <code>auto_docstring.py</code>.</p></blockquote> <ul><li>Vérifie que <code>@auto_docstring</code> est appliqué aux classes de modèles et méthodes publiques concernées.</li> <li>Valide l’exhaustivité et la cohérence des arguments : les arguments documentés doivent exister dans la signature, et les types et valeurs par défaut doivent correspondre. Les arguments inconnus sans description locale sont signalés.</li> <li>Détecte les espaces réservés incomplets tels que <code><fill_type></code> et <code><fill_docstring></code>.</li> <li>Vérifie que les docstrings respectent le style de formatage attendu.</li></ul> <p>Exécutez la vérification localement avant de valider.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-bash "><!---->make fix-repo<!----></pre></div><!----> <p><code>make fix-repo</code> exécute également plusieurs autres vérifications. Pour n’exécuter que les vérifications de docstring et de docstring automatique, utilisez la commande ci-dessous.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-comment"># to only check files included in the diff without fixing them</span> | |
| python utils/check_docstrings.py | |
| <span class="hljs-comment"># to fix and overwrite the files in the diff</span> | |
| <span class="hljs-comment"># python utils/check_docstrings.py --fix_and_overwrite</span> | |
| <span class="hljs-comment"># to fix and overwrite all files</span> | |
| <span class="hljs-comment"># python utils/check_docstrings.py --fix_and_overwrite --check_all</span><!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="quick-reference-checklist" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#quick-reference-checklist"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Liste de contrôle de référence rapide<!----></span></h2><!--]--><!----> <table><thead><tr><th>Faire</th><th>Ne</th></tr></thead><tbody><tr><td>Appliquez <code>@auto_docstring</code> aux classes de modèle, de configuration et de processeur ainsi qu'à leurs méthodes principales (<code>forward</code>, <code>__call__</code>, <code>preprocess</code>).</td><td>Ajoutez <code>@auto_docstring</code> aux modèles hérités dans les fichiers modulaires, car il est repris automatiquement.</td></tr><tr><td>Documentez uniquement les nouveaux arguments ou les arguments spécifiques au modèle.</td><td>Redefinir les arguments standard (<code>input_ids</code>, <code>attention_mask</code>, <code>vocab_size</code>, etc.) qui se comportent de la même manière que leurs descriptions par défaut.</td></tr><tr><td>Placez les paramètres de configuration dans la docstring du corps de la classe en tant qu'annotations de niveau classe.</td><td>Placez les paramètres de configuration dans <code>__init__</code>.</td></tr><tr><td>Placez les paramètres du processeur d’images dans un TypedDict <code>XxxImageProcessorKwargs</code>.</td><td>Placez les paramètres du processeur d'images dans <code>__init__</code>.</td></tr><tr><td>Exécutez <code>python utils/check_docstrings.py --fix_and_overwrite</code> avant de committer.</td><td>Ignorez la sortie <code>[ERROR]</code> car elle signifie qu'un paramètre n'est pas documenté.</td></tr></tbody></table> <!--[1--><h2 class="relative group"><a id="how-it-works" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#how-it-works"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Fonctionnement<!----></span></h2><!--]--><!----> <p>Le décorateur <code>@auto_docstring</code> génère des docstrings selon les étapes suivantes.</p> <ol><li><p>Le décorateur inspecte la signature pour lire les arguments, les types et les valeurs par défaut depuis le <code>__init__</code> de la classe décorée ou depuis la fonction décorée. Pour les classes de configuration, il parcourt les annotations au niveau de la classe le long de la chaîne d'héritage et s'arrête avant <a href="/docs/transformers/main/fr/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a>, excluant ainsi les champs des classes de base.</p> <p>Il filtre automatiquement des paramètres tels que <code>self</code>, <code>kwargs</code>, <code>args</code>, <code>deprecated_arguments</code> et les noms préfixés par <code>_</code>. Certains paramètres privés sont renommés en leurs équivalents publics (<code>_out_features</code> → <code>out_features</code> pour les modèles backbone).</p></li> <li><p>Les descriptions d’arguments courantes proviennent de <code>auto_docstring.py</code> : <code>ModelArgs</code> (entrées du modèle), <code>ModelOutputArgs</code> (champs de sortie tels que <code>hidden_states</code>), <code>ImageProcessorArgs</code> (prétraitement des images), <code>ProcessorArgs</code> (composants du processeur multimodal) et <code>ConfigArgs</code> (hyperparamètres de configuration).</p></li> <li><p>La description de chaque paramètre suit cette chaîne de priorité :</p> <ul><li>Une docstring manuelle (bloc <code>r""" """</code> ou <code>custom_args</code>) a la priorité.</li> <li>Le dictionnaire source prédéfini (<code>ModelArgs</code>, <code>ModelForArgs</code>, <code>ConfigArgs</code>, <code>ImageProcessorArgs</code>, <code>ProcessorArgs</code>, <code>ModelOutputArgs</code>) sert de repli.</li> <li>Si aucune des sources ne contient de description, le paramètre est signalé avec <code>[ERROR]</code> dans la sortie de compilation.</li></ul></li> <li><p>Pour les classes de modèles aux noms standards comme <code>ModelForCausalLM</code>, ou les classes qui correspondent à un pipeline, <code>@auto_docstring</code> génère l’introduction. Pour les processeurs multimodaux, l’introduction énumère les composants (tokenizer, image processor, etc.) que la classe encapsule. Consultez <a href="https://github.com/huggingface/transformers/blob/main/src/transformers/utils/auto_docstring.py#L2437" rel="nofollow">ClassDocstring</a> pour la liste complète.</p> <p>Si le nom de la classe n’est pas dans <code>ClassDocstring</code>, définissez <code>custom_intro</code>.</p></li> <li><p>Les docstrings prédéfinies peuvent référencer des valeurs dynamiques des <a href="https://github.com/huggingface/transformers/tree/main/src/transformers/models/auto" rel="nofollow">auto_modules</a> de Transformers, telles que <code>{processor_class}</code>, <code>{image_processor_class}</code> et <code>{config_class}</code>. Les espaces réservés sont résolus automatiquement.</p></li> <li><p>Le décorateur sélectionne des exemples d’utilisation en fonction de la tâche ou de la compatibilité pipeline du modèle. Il lit les métadonnées du checkpoint depuis la classe de configuration afin que les exemples utilisent de vrais identifiants de modèles. L’argument <code>checkpoint</code> remplace le checkpoint déduit de la docstring de la classe de configuration. Définissez <code>checkpoint</code> sur les classes de configuration, ou lorsque la déduction du checkpoint échoue. Si vous voyez une erreur comme <code>"Config not found for <model_name>"</code>, ajoutez une entrée à <code>HARDCODED_CONFIG_FOR_MODELS</code> dans <code>auto_docstring.py</code>.</p></li> <li><p>Pour des méthodes comme <code>forward</code>, le décorateur rédige la section <code>Returns</code> à partir du type de retour de la méthode. Lorsque le type de retour est un sous-classe de <a href="/docs/transformers/main/fr/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a>, <code>@auto_docstring</code> extrait les descriptions des champs depuis la docstring de cette classe. Un bloc <code>Returns</code> personnalisé dans la docstring de la fonction prend le pas.</p></li> <li><p>Pour les méthodes de <code>UNROLL_KWARGS_METHODS</code> et les classes de <code>UNROLL_KWARGS_CLASSES</code>, le décorateur développe <code>**kwargs</code> typé avec <code>Unpack[KwargsTypedDict]</code>. Chaque clé du <code>TypedDict</code> devient un paramètre documenté.</p> <p>La même expansion s’applique aux méthodes <code>__call__</code> et <code>preprocess</code> des sous-classes de <a href="/docs/transformers/main/fr/main_classes/image_processor#transformers.BaseImageProcessor">BaseImageProcessor</a> et <a href="/docs/transformers/main/fr/main_classes/processors#transformers.ProcessorMixin">ProcessorMixin</a>. Les types de base génériques (<code>TextKwargs</code>, <code>ImagesKwargs</code>, <code>VideosKwargs</code>, <code>AudioKwargs</code>) sont ignorés. Seules les sous-classes spécifiques à un modèle sont dépliées.</p></li></ol> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/transformers/blob/main/docs/source/en/auto_docstring.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]--> | |
| <script> | |
| { | |
| __sveltekit_1m6yd5j = { | |
| base: "/docs/transformers/main/en", | |
| assets: "/docs/transformers/main/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/transformers/main/en/_app/immutable/entry/start.DYIO-UII.js"), | |
| import("/docs/transformers/main/en/_app/immutable/entry/app.D2_KizbC.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 11], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 71.7 kB
- Xet hash:
- 8e3eb1f12066f32ffcabbc9383b00b139f5124a3bb9d5f79067f12cf09e0f0b1
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.