Buckets:

hf-doc-build/doc / transformers /main /ro /auto_docstring.html
HuggingFaceDocBuilder's picture
download
raw
69.3 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Auto-generarea docstring-urilor&quot;,&quot;local&quot;:&quot;auto-generarea-docstring-urilor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;@auto_docstring&quot;,&quot;local&quot;:&quot;autodocstring&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Utilizare&quot;,&quot;local&quot;:&quot;utilizare&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Clase de model&quot;,&quot;local&quot;:&quot;clase-de-model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Clase de config&quot;,&quot;local&quot;:&quot;clase-de-config&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Clase de procesator&quot;,&quot;local&quot;:&quot;clase-de-procesator&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Procesatoare de imagini și video&quot;,&quot;local&quot;:&quot;procesatoare-de-imagini-și-video&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Funcții&quot;,&quot;local&quot;:&quot;funcții&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Documentarea argumentelor&quot;,&quot;local&quot;:&quot;documentarea-argumentelor&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Verificarea docstring-urilor&quot;,&quot;local&quot;:&quot;verificarea-docstring-urilor&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Checklist de referință rapidă&quot;,&quot;local&quot;:&quot;checklist-de-referință-rapidă&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Cum funcționează&quot;,&quot;local&quot;:&quot;cum-funcționează&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/transformers/main/ro/_app/immutable/entry/start.Cj0_j3du.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/CUCuKvpH.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/Dm_uEeBC.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/entry/app.2x2TdrVN.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/BFzpZI28.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/DM0RASQS.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/DJ5hodCp.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/GYau11Sm.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/nodes/0.BonRETMf.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/B1k23FAg.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/utTYfj_T.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/nodes/6.DtRSXur1.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/BcKuJYrM.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/BGhUAj7r.js" rel="modulepreload">
<!--1wlpssc--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Auto-generarea docstring-urilor&quot;,&quot;local&quot;:&quot;auto-generarea-docstring-urilor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;@auto_docstring&quot;,&quot;local&quot;:&quot;autodocstring&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Utilizare&quot;,&quot;local&quot;:&quot;utilizare&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Clase de model&quot;,&quot;local&quot;:&quot;clase-de-model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Clase de config&quot;,&quot;local&quot;:&quot;clase-de-config&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Clase de procesator&quot;,&quot;local&quot;:&quot;clase-de-procesator&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Procesatoare de imagini și video&quot;,&quot;local&quot;:&quot;procesatoare-de-imagini-și-video&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Funcții&quot;,&quot;local&quot;:&quot;funcții&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Documentarea argumentelor&quot;,&quot;local&quot;:&quot;documentarea-argumentelor&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Verificarea docstring-urilor&quot;,&quot;local&quot;:&quot;verificarea-docstring-urilor&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Checklist de referință rapidă&quot;,&quot;local&quot;:&quot;checklist-de-referință-rapidă&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Cum funcționează&quot;,&quot;local&quot;:&quot;cum-funcționează&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/transformers/main/ro/_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: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div 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>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-generarea-docstring-urilor" 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-generarea-docstring-urilor"><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-generarea docstring-urilor</span></h1><!--]--><!----> <p>Decoratorul <code>@auto_docstring</code> generează docstring-uri consistente pentru clasele și metodele de model. Trage automat descrierile standard ale argumentelor, deci scrii documentație doar pentru argumentele noi sau personalizate. Când <a href="./modular_transformers">adaugi un model nou</a>, sari peste boilerplate și concentrează-te pe ce e nou.</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>Importă decoratorul în fișierul tău <code>modular_model.py</code> (sau <code>modeling_model.py</code> pentru modele mai vechi).</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> Copied</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>Dacă modelul tău moștenește dintr-un alt model din librărie într-un fișier modular, <code>@auto_docstring</code> este deja aplicat în părinte. <code>make fix-repo</code> îl copiază în fișierul <code>modeling_model.py</code> generat. Aplică decoratorul explicit doar ca să personalizezi comportamentul (modele standalone, intro-uri personalizate sau argumente suprascrise).</p> <blockquote class="warning"><p>Când suprascrii orice decorator într-un fișier modular, include <strong>toți</strong> decoratorii din funcția sau clasa părinte. Dacă suprascrii doar unii, restul nu vor apărea în fișierul de modelare generat.</p></blockquote> <p>Decoratorul acceptă următoarele argumente opționale:</p> <table><thead><tr><th>argument</th><th>descriere</th></tr></thead><tbody><tr><td><code>custom_intro</code></td><td>O descriere a clasei sau metodei, inserată înainte de secțiunea Args. Necesară pentru clasele al căror nume nu se termină cu un <a href="#cum-func%C8%9Bioneaz%C4%83">sufix recunoscut</a> precum <code>ForCausalLM</code> sau <code>ForTokenClassification</code>.</td></tr><tr><td><code>custom_args</code></td><td>Text de docstring pentru parametri specifici. Util când aceleași argumente personalizate apar în mai multe locuri din fișierul de modelare.</td></tr><tr><td><code>checkpoint</code></td><td>Un identificator de checkpoint (<code>"org/my-model"</code>) folosit ca să genereze exemple de utilizare. Suprascrie checkpoint-ul dedus automat din clasa de config. Se setează de obicei pe clasele de config.</td></tr></tbody></table> <!--[1--><h2 class="relative group"><a id="utilizare" 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="#utilizare"><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>Utilizare</span></h2><!--]--><!----> <p>Cum funcționează <code>@auto_docstring</code> depinde de ce decorezi. Clasele de model trag documentația parametrilor din <code>__init__</code>, clasele de config trag din adnotările la nivel de clasă, clasele de procesor auto-generează intro-uri din componentele lor, iar metodele precum <code>forward</code> primesc tipuri de returnare și exemple de utilizare.</p> <!--[2--><h3 class="relative group"><a id="clase-de-model" 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="#clase-de-model"><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>Clase de model</span></h3><!--]--><!----> <p>Pune <code>@auto_docstring</code> direct deasupra definiției clasei. Decoratorul derivă descrierile parametrilor din semnătura și docstring-ul metodei <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> Copied</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">&quot;default&quot;</span></span>):
<span class="hljs-string">r&quot;&quot;&quot;
custom_parameter (`int`, *optional*, defaults to 10):
Descrierea custom_parameter pentru MyAwesomeModel.
another_custom_arg (`str`, *optional*, defaults to &quot;default&quot;):
Documentație pentru un alt argument unic.
&quot;&quot;&quot;</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"># ... restul init-ului tău</span>
<span class="hljs-comment"># ... alte metode</span><!----></pre></div><!----> <p>Pasează <code>custom_intro</code> și <code>custom_args</code> pentru mai mult control. Argumentele personalizate pot merge în <code>custom_args</code> sau în docstring-ul <code>__init__</code>. Folosește <code>custom_args</code> când aceleași argumente se repetă în mai multe metode.</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> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-meta">@auto_docstring(<span class="hljs-params">
custom_intro=<span class="hljs-string">&quot;&quot;&quot;Acest model efectuează operații sinergice specifice.
Se construiește pe arhitectura standard Transformer cu modificări unice.&quot;&quot;&quot;</span>,
custom_args=<span class="hljs-string">&quot;&quot;&quot;
custom_parameter (`type`, *optional*, defaults to `default_value`):
O descriere concisă pentru custom_parameter dacă nu este definit sau suprascrie descrierea din `auto_docstring.py`.
internal_helper_arg (`type`, *optional*, defaults to `default_value`):
O descriere concisă pentru internal_helper_arg dacă nu este definit sau suprascrie descrierea din `auto_docstring.py`.
&quot;&quot;&quot;</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">&quot;type&quot;</span> = <span class="hljs-string">&quot;default_value&quot;</span>, internal_helper_arg=<span class="hljs-literal">None</span></span>):
<span class="hljs-comment"># ...</span><!----></pre></div><!----> <p>Aplică <code>@auto_docstring</code> și la clasele care moștenesc din <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> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-meta">@auto_docstring(<span class="hljs-params">
custom_intro=<span class="hljs-string">&quot;&quot;&quot;
Ieșiri personalizate ale modelului cu câmpuri suplimentare.
&quot;&quot;&quot;</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&quot;&quot;&quot;
loss (`torch.FloatTensor`, *optional*):
Loss-ul modelului.
custom_field (`torch.FloatTensor` of shape `(batch_size, hidden_size)`, *optional*):
Un câmp de ieșire personalizat specific acestui model.
&quot;&quot;&quot;</span>
<span class="hljs-comment"># Câmpurile standard (hidden_states, logits, attentions, etc.) sunt documentate automat când</span>
<span class="hljs-comment"># descrierea corespunde textului standard. Loss-ul variază de obicei per model, deci documentează-l mai sus.</span>
loss: <span class="hljs-type">Optional</span>[torch.FloatTensor] = <span class="hljs-literal">None</span>
logits: <span class="hljs-type">Optional</span>[torch.FloatTensor] = <span class="hljs-literal">None</span>
hidden_states: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">tuple</span>[torch.FloatTensor, ...]] = <span class="hljs-literal">None</span>
attentions: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">tuple</span>[torch.FloatTensor, ...]] = <span class="hljs-literal">None</span>
<span class="hljs-comment"># Câmpurile personalizate trebuie documentate în docstring-ul de mai sus</span>
custom_field: <span class="hljs-type">Optional</span>[torch.FloatTensor] = <span class="hljs-literal">None</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="clase-de-config" 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="#clase-de-config"><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>Clase de config</span></h3><!--]--><!----> <p>Pune <code>@auto_docstring</code> direct deasupra unei subclase <code>PreTrainedConfig</code>, alături de decoratorul <code>@strict</code>. <code>@strict</code> adaugă validarea de tip la runtime și transformă clasa într-un dataclass validat. Parametrii de config sunt <em>adnotări la nivel de clasă</em> (nu argumente <code>__init__</code>), iar <code>@auto_docstring</code> îi citește din corpul clasei ca să genereze docs.</p> <p><code>ConfigArgs</code> furnizează parametri standard precum <code>vocab_size</code>, <code>hidden_size</code> și <code>num_hidden_layers</code>, deci nu au nevoie de descriere dacă comportamentul nu diferă. Parametrii de bază <code>PreTrainedConfig</code> sunt excluși automat. Argumentul <code>checkpoint</code> generează exemplul de utilizare.</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> Copied</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">&quot;org/my-model-checkpoint&quot;</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&quot;&quot;&quot;
custom_param (`int`, *optional*, defaults to 64):
Descrierea unui parametru specific acestui model.
another_param (`str`, *optional*, defaults to `&quot;gelu&quot;`):
Descrierea unui alt parametru specific modelului.
```python
&gt;&gt;&gt; from transformers import MyModelConfig, MyModel
&gt;&gt;&gt; configuration = MyModelConfig()
&gt;&gt;&gt; model = MyModel(configuration)
&gt;&gt;&gt; configuration = model.config
```
&quot;&quot;&quot;</span>
model_type = <span class="hljs-string">&quot;my_model&quot;</span>
<span class="hljs-comment"># Parametrii standard (vocab_size, hidden_size, etc.) sunt auto-documentați din 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"># Parametrii specifici modelului trebuie documentați în docstring-ul clasei de mai sus.</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">&quot;gelu&quot;</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="clase-de-procesator" 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="#clase-de-procesator"><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>Clase de procesator</span></h3><!--]--><!----> <p>Procesoarele multimodale (subclase <code>ProcessorMixin</code>, <code>processing_*.py</code>) folosesc întotdeauna <code>@auto_docstring</code> simplu. Intro-ul clasei este auto-generat. Documentează doar parametrii <code>__init__</code> care nu sunt deja acoperiți de <code>ProcessorArgs</code> (<code>image_processor</code>, <code>tokenizer</code>, <code>chat_template</code> și alții).</p> <p>Dacă fiecare parametru este standard, omite docstring-ul. Decorează și <code>__call__</code> cu <code>@auto_docstring</code>. Docstring-ul corpului său conține doar o secțiune <code>Returns:</code> plus orice argumente de apel suplimentare specifice modelului. <code>return_tensors</code> este adăugat automat.</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> Copied</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>):
_defaults = {<span class="hljs-string">&quot;text_kwargs&quot;</span>: {<span class="hljs-string">&quot;padding&quot;</span>: <span class="hljs-literal">False</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>):
<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&quot;&quot;&quot;
custom_param (`int`, *optional*, defaults to 4):
Un parametru specific acestui procesor, neacoperit de ProcessorArgs standard.
&quot;&quot;&quot;</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&quot;&quot;&quot;
Returns:
`BatchFeature`: Un `BatchFeature` cu următoarele câmpuri:
- **input_ids** -- Token ids de pasat modelului.
- **pixel_values** -- Valori pixel de pasat modelului.
&quot;&quot;&quot;</span>
<span class="hljs-comment"># ...</span><!----></pre></div><!----> <!--[3--><h4 class="relative group"><a id="procesatoare-de-imagini-și-video" 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="#procesatoare-de-imagini-și-video"><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>Procesatoare de imagini și video</span></h4><!--]--><!----> <p>Procesatoarele de imagini și video (subclase <code>BaseImageProcessor</code>, <code>image_processing_*.py</code>) urmează unul din două pattern-uri.</p> <p>Dacă procesorul are parametri specifici modelului, definești un <code>TypedDict</code> <code>XxxImageProcessorKwargs(ImagesKwargs, total=False)</code> cu un docstring pentru acei parametri, setezi <code>valid_kwargs</code> pe clasă și folosești <code>@auto_docstring</code> simplu. <code>__init__</code> nu are 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> Copied</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&quot;&quot;&quot;
custom_threshold (`float`, *optional*, defaults to `self.custom_threshold`):
Un parametru specific acestui procesor de imagini.
&quot;&quot;&quot;</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>Dacă clasa setează doar atribute standard la nivel de clasă (<code>size</code>, <code>resample</code>, <code>image_mean</code> etc.) fără kwargs personalizate, folosește <code>@auto_docstring(custom_intro="Constructs a MyModel image processor.")</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> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-meta">@auto_docstring(<span class="hljs-params">custom_intro=<span class="hljs-string">&quot;Constructs a MyModel image processor.&quot;</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">&quot;height&quot;</span>: <span class="hljs-number">224</span>, <span class="hljs-string">&quot;width&quot;</span>: <span class="hljs-number">224</span>}<!----></pre></div><!----> <p>Când suprascrii <code>preprocess</code>, decorează-l cu <code>@auto_docstring</code> și documentează doar argumentele care nu sunt în <code>ImageProcessorArgs</code>. Argumentele standard și <code>return_tensors</code> sunt incluse automat.</p> <!--[2--><h3 class="relative group"><a id="funcții" 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="#funcții"><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>Funcții</span></h3><!--]--><!----> <p>Pune <code>@auto_docstring</code> direct deasupra definiției funcției. Decoratorul derivă descrierile parametrilor din semnătura funcției.</p> <p>Decoratorul generează textul valorii de returnare din docstring-ul clasei <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> Copied</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"># ... alte argumente</span>
</span>) -&gt; <span class="hljs-type">Union</span>[<span class="hljs-type">Tuple</span>, ModelOutput]:
<span class="hljs-string">r&quot;&quot;&quot;
new_custom_argument (`torch.Tensor`, *optional*):
Descrierea acestui argument personalizat nou și forma sau tipul așteptat.
&quot;&quot;&quot;</span>
<span class="hljs-comment"># ...</span><!----></pre></div><!----> <p>Pasează <code>custom_intro</code> și <code>custom_args</code> pentru mai mult control. Folosește <code>custom_args</code> ca să definești documentația argumentelor partajate o singură dată când aceiași parametri apar în mai multe metode.</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> Copied</div><!----></button><!----></div> <pre class="language-python "><!---->MODEL_COMMON_CUSTOM_ARGS = <span class="hljs-string">r&quot;&quot;&quot;
common_arg_1 (`torch.Tensor`, *optional*, defaults to `default_value`):
Descrierea lui common_arg_1
common_arg_2 (`torch.Tensor`, *optional*, defaults to `default_value`):
Descrierea lui common_arg_2
&quot;&quot;&quot;</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">&quot;&quot;&quot;Acesta este un intro personalizat pentru funcție.&quot;&quot;&quot;</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>) -&gt; ModelOutput:
<span class="hljs-string">r&quot;&quot;&quot;argumente specifice metodei merg aici&quot;&quot;&quot;</span>
<span class="hljs-comment"># ...</span><!----></pre></div><!----> <p>Scrie secțiunile <code>Returns</code> și <code>Examples</code> manual în docstring ca să suprascrii versiunile auto-generate.</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> Copied</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>) -&gt; torch.Tensor:
<span class="hljs-string">r&quot;&quot;&quot;
Returns:
`torch.Tensor`: O secțiune Returns personalizată pentru tipuri de returnare non-ModelOutput.
Example:
```python
&gt;&gt;&gt; model = MyModel.from_pretrained(&quot;org/my-model&quot;)
&gt;&gt;&gt; output = model(input_ids)
```
&quot;&quot;&quot;</span>
<span class="hljs-comment"># ...</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="documentarea-argumentelor" 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="#documentarea-argumentelor"><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>Documentarea argumentelor</span></h3><!--]--><!----> <p>Urmează aceste reguli când documentezi tipuri diferite de argumente.</p> <ul><li><p><code>auto_docstring.py</code> definește argumentele standard (<code>input_ids</code>, <code>attention_mask</code>, <code>pixel_values</code> etc.) și le include automat. Nu le redefini local dacă argumentul se comportă la fel ca în modelul tău.</p> <p>Dacă un argument standard se comportă diferit în modelul tău, suprascrie-l local într-un bloc <code>r""" """</code>. Definiția locală are prioritate. Argumentul <code>labels</code>, de exemplu, este personalizat des per model și necesită să fie suprascris.</p></li> <li><p>Argumentele standard de config (<code>vocab_size</code>, <code>hidden_size</code>, <code>num_hidden_layers</code> etc.) urmează același principiu, dar vin din <code>ConfigArgs</code>. Argumentele standard de procesor (<code>image_processor</code>, <code>tokenizer</code>, <code>do_resize</code>, <code>return_tensors</code> etc.) vin din <code>ProcessorArgs</code> și <code>ImageProcessorArgs</code>. Documentează un parametru doar dacă este specific modelului sau se comportă diferit față de descrierea standard.</p></li> <li><p>Documentează argumentele noi sau personalizate într-un bloc <code>r""" """</code>. Pune-le după semnătură pentru funcții, în docstring-ul <code>__init__</code> pentru clase de model sau procesor, în docstring-ul corpului clasei pentru clase de config, sau în corpul <code>TypedDict</code>-ului <code>XxxImageProcessorKwargs</code> pentru procesoare de imagini.</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> Copied</div><!----></button><!----></div> <pre class="language-py "><!---->argument_name (`<span class="hljs-built_in">type</span>`, *optional*, defaults to `X`):
Descrierea argumentului.
Explică scopul, forma/tipul așteptat dacă e <span class="hljs-built_in">complex</span> și comportamentul implicit.
Poate fi pe mai multe linii.<!----></pre></div><!----> <ul><li>Include <code>type</code> în backticks.</li> <li>Adaugă <em>optional</em> dacă argumentul nu este obligatoriu sau are o valoare implicită.</li> <li>Adaugă “defaults to X” dacă are o valoare implicită. Nu trebuie să adaugi “defaults to <code>None</code>” dacă valoarea implicită este <code>None</code>.</li> <li>Pasează același bloc în <code>custom_args</code> când aceleași argumente se repetă în mai multe metode (vezi <a href="#func%C8%9Bii">exemplul cu Funcții de mai sus</a>).</li></ul></li> <li><p>Decoratorul extrage tipurile din semnăturile funcțiilor automat. Dacă un parametru are o adnotare de tip, nu trebuie să repeți tipul în format string în docstring. Când ambele sunt prezente, tipul semnăturii are prioritate. Tipul din docstring acționează ca fallback pentru parametrii fără adnotare.</p></li></ul> <!--[1--><h2 class="relative group"><a id="verificarea-docstring-urilor" 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="#verificarea-docstring-urilor"><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>Verificarea docstring-urilor</span></h2><!--]--><!----> <p>Un script utilitar validează docstring-urile când deschizi un pull request. CI rulează scriptul și verifică următoarele.</p> <blockquote class="tip"><p>Dacă vezi <code>[ERROR]</code> în output, adaugă descrierea parametrului în docstring sau în clasa Args corespunzătoare din <code>auto_docstring.py</code>.</p></blockquote> <ul><li>Verifică că <code>@auto_docstring</code> este aplicat la clasele de model relevante și metodele publice.</li> <li>Validează completitudinea și consistența argumentelor: argumentele documentate trebuie să existe în semnătură, iar tipurile și valorile implicite trebuie să corespundă. Argumentele necunoscute fără o descriere locală sunt semnalate.</li> <li>Semnalează placeholder-urile incomplete precum <code>&lt;fill_type></code> și <code>&lt;fill_docstring></code>.</li> <li>Verifică că docstring-urile urmează stilul de formatare așteptat.</li></ul> <p>Rulează verificarea local înainte de commit.</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> Copied</div><!----></button><!----></div> <pre class="language-bash "><!---->make fix-repo<!----></pre></div><!----> <p><code>make fix-repo</code> rulează și alte verificări. Ca să rulezi doar verificările de docstring și auto-docstring, folosește comanda de mai jos.</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> Copied</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-comment"># verifică doar fișierele incluse în diff fără să le remedieze</span>
python utils/check_docstrings.py
<span class="hljs-comment"># remediază și suprascrie fișierele din diff</span>
<span class="hljs-comment"># python utils/check_docstrings.py --fix_and_overwrite</span>
<span class="hljs-comment"># remediază și suprascrie toate fișierele</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="checklist-de-referință-rapidă" 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="#checklist-de-referință-rapidă"><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>Checklist de referință rapidă</span></h2><!--]--><!----> <table><thead><tr><th></th><th>Nu face</th></tr></thead><tbody><tr><td>Aplică <code>@auto_docstring</code> la clasele de model, config și procesor și metodele lor principale (<code>forward</code>, <code>__call__</code>, <code>preprocess</code>).</td><td>Adaugă <code>@auto_docstring</code> la modelele moștenite în fișierele modulare pentru că se transferă automat.</td></tr><tr><td>Documentează doar argumentele noi sau specifice modelului.</td><td>Redefinește argumentele standard (<code>input_ids</code>, <code>attention_mask</code>, <code>vocab_size</code> etc.) care se comportă la fel cu descrierile lor implicite.</td></tr><tr><td>Pune parametrii de config în docstring-ul corpului clasei ca adnotări la nivel de clasă.</td><td>Pune parametrii de config în <code>__init__</code>.</td></tr><tr><td>Pune parametrii procesorului de imagini într-un <code>TypedDict</code> <code>XxxImageProcessorKwargs</code>.</td><td>Pune parametrii procesorului de imagini în <code>__init__</code>.</td></tr><tr><td>Rulează <code>python utils/check_docstrings.py --fix_and_overwrite</code> înainte de commit.</td><td>Ignoră ieșirile <code>[ERROR]</code> pentru că înseamnă că un parametru este nedocumentat.</td></tr></tbody></table> <!--[1--><h2 class="relative group"><a id="cum-funcționează" 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="#cum-funcționează"><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>Cum funcționează</span></h2><!--]--><!----> <p>Decoratorul <code>@auto_docstring</code> generează docstring-uri prin pașii următori.</p> <ol><li><p>Decoratorul inspectează semnătura ca să citească argumentele, tipurile și valorile implicite din <code>__init__</code>-ul clasei decorate sau din funcția decorată. Pentru clasele de config, parcurge adnotările la nivel de clasă în sus pe lanțul de moștenire și se oprește înainte de <code>PreTrainedConfig</code>, excluzând câmpurile clasei de bază.</p> <p>Filtrează automat parametri precum <code>self</code>, <code>kwargs</code>, <code>args</code>, <code>deprecated_arguments</code> și nume cu prefix <code>_</code>. Câțiva parametri privați sunt redenumiți la echivalentele lor publice (<code>_out_features</code><code>out_features</code> pentru modele backbone).</p></li> <li><p>Descrierile comune ale argumentelor vin din <code>auto_docstring.py</code>: <code>ModelArgs</code> (inputuri model), <code>ModelOutputArgs</code> (câmpuri de ieșire precum <code>hidden_states</code>), <code>ImageProcessorArgs</code> (preprocesare imagini), <code>ProcessorArgs</code> (componente procesor multimodal) și <code>ConfigArgs</code> (hyperparameteri de config).</p></li> <li><p>Descrierea fiecărui parametru urmează acest lanț de prioritate:</p> <ul><li>Un docstring manual (bloc <code>r""" """</code> sau <code>custom_args</code>) are prioritate.</li> <li>Dicționarul de surse predefinit (<code>ModelArgs</code>, <code>ConfigArgs</code>, <code>ImageProcessorArgs</code>, <code>ProcessorArgs</code>, <code>ModelOutputArgs</code>) este fallback-ul.</li> <li>Dacă nicio sursă nu are o descriere, parametrul este semnalat cu <code>[ERROR]</code> în ieșirea de build.</li></ul></li> <li><p>Pentru clasele de model cu nume standard precum <code>ModelForCausalLM</code>, sau clasele care mapează la un pipeline, <code>@auto_docstring</code> generează intro-ul. Pentru procesoarele multimodale, intro-ul listează ce componente (tokenizer, procesor de imagini etc.) dau wrap clasei. Vezi <a href="https://github.com/huggingface/transformers/blob/main/src/transformers/utils/auto_docstring.py#L2437" rel="nofollow">ClassDocstring</a> pentru lista completă.</p> <p>Dacă numele clasei nu este în <code>ClassDocstring</code>, setează <code>custom_intro</code>.</p></li> <li><p>Docstring-urile predefinite pot face referire la valori dinamice din <a href="https://github.com/huggingface/transformers/tree/main/src/transformers/models/auto" rel="nofollow">auto_modules</a> Transformers, cum ar fi <code>{processor_class}</code>, <code>{image_processor_class}</code> și <code>{config_class}</code>. Placeholder-urile se rezolvă automat.</p></li> <li><p>Decoratorul alege exemple de utilizare bazat pe task-ul sau compatibilitatea cu pipeline a modelului. Citește metadatele checkpoint-ului din clasa de configurare ca exemplele să folosească ID-uri reale de model. Argumentul <code>checkpoint</code> suprascrie checkpoint-ul dedus din docstring-ul clasei de config. Setează <code>checkpoint</code> pe clasele de config sau când deducerea checkpoint-ului eșuează. Dacă vezi o eroare precum <code>"Config not found for &lt;model_name>"</code>, adaugă o intrare în <code>HARDCODED_CONFIG_FOR_MODELS</code> din <code>auto_docstring.py</code>.</p></li> <li><p>Pentru metode precum <code>forward</code>, decoratorul scrie secțiunea <code>Returns</code> din tipul de returnare al metodei. Când tipul de returnare este o subclasă <code>ModelOutput</code>, <code>@auto_docstring</code> trage descrierile câmpurilor din docstring-ul acelei clase. Un bloc <code>Returns</code> personalizat în docstring-ul funcției are prioritate.</p></li> <li><p>Pentru metodele din <code>UNROLL_KWARGS_METHODS</code> și clasele din <code>UNROLL_KWARGS_CLASSES</code>, decoratorul expandează <code>**kwargs</code> tipizat cu <code>Unpack[KwargsTypedDict]</code>. Fiecare cheie din <code>TypedDict</code> devine un parametru documentat.</p> <p>Aceeași expandare se aplică metodelor <code>__call__</code> și <code>preprocess</code> pe subclasele <code>BaseImageProcessor</code> și <code>ProcessorMixin</code>. Tipurile de bază generice (<code>TextKwargs</code>, <code>ImagesKwargs</code>, <code>VideosKwargs</code>, <code>AudioKwargs</code>) sunt sărite. Doar subclasele specifice modelului sunt expandate.</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/ro/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_1piag1k = {
base: "/docs/transformers/main/ro",
assets: "/docs/transformers/main/ro"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/transformers/main/ro/_app/immutable/entry/start.Cj0_j3du.js"),
import("/docs/transformers/main/ro/_app/immutable/entry/app.2x2TdrVN.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 6],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
69.3 kB
·
Xet hash:
ef549b2ca506f385e9223239db9148ab4d058a5900747637e92469af5a2e1e35

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.