Buckets:

hf-doc-build/doc / transformers /main /ro /modular_transformers.html
HuggingFaceDocBuilder's picture
download
raw
107 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Adaugă un model cu transformers modulare&quot;,&quot;local&quot;:&quot;adaugă-un-model-cu-transformers-modulare&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Implementarea unui fișier modular&quot;,&quot;local&quot;:&quot;implementarea-unui-fișier-modular&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Config&quot;,&quot;local&quot;:&quot;config&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Norm&quot;,&quot;local&quot;:&quot;norm&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Attention&quot;,&quot;local&quot;:&quot;attention&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;DecoderLayer&quot;,&quot;local&quot;:&quot;decoderlayer&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Model&quot;,&quot;local&quot;:&quot;model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Model head&quot;,&quot;local&quot;:&quot;model-head&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Alte clase&quot;,&quot;local&quot;:&quot;alte-clase&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Finalizarea fișierului&quot;,&quot;local&quot;:&quot;finalizarea-fișierului&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Generarea fișierelor de modelare&quot;,&quot;local&quot;:&quot;generarea-fișierelor-de-modelare&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Tipare pentru fișierele modulare&quot;,&quot;local&quot;:&quot;tipare-pentru-fișierele-modulare&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Eliminarea atributelor&quot;,&quot;local&quot;:&quot;eliminarea-atributelor&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Utilizarea super()&quot;,&quot;local&quot;:&quot;utilizarea-super&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Apelarea directă a unui strămoș&quot;,&quot;local&quot;:&quot;apelarea-directă-a-unui-strămoș&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;super_kwargs&quot;,&quot;local&quot;:&quot;superkwargs&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Ștergerea metodelor neutilizate&quot;,&quot;local&quot;:&quot;ștergerea-metodelor-neutilizate&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Suprascrierea metodelor decorate&quot;,&quot;local&quot;:&quot;suprascrierea-metodelor-decorate&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Denumire specială&quot;,&quot;local&quot;:&quot;denumire-specială&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Docstring-uri pentru config&quot;,&quot;local&quot;:&quot;docstring-uri-pentru-config&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Conversia checkpoint-urilor&quot;,&quot;local&quot;:&quot;conversia-checkpoint-urilor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Scrie un script de conversie&quot;,&quot;local&quot;:&quot;scrie-un-script-de-conversie&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Maparea conversiei la runtime&quot;,&quot;local&quot;:&quot;maparea-conversiei-la-runtime&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Pașii următori&quot;,&quot;local&quot;:&quot;pașii-următori&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/transformers/main/ro/_app/immutable/entry/start.CIgIKwFw.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/BcwjRHJP.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/Cl6kX2N0.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/entry/app.eNKDC4Vf.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/BzzeShVL.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/DWwSmaYb.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/nodes/0.P_YGbUHv.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/C8aKV6he.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/nodes/22.Bu_nNIoz.js" rel="modulepreload">
<link href="/docs/transformers/main/ro/_app/immutable/chunks/CjTxHwdC.js" rel="modulepreload">
<!--1rp9gg8--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Adaugă un model cu transformers modulare&quot;,&quot;local&quot;:&quot;adaugă-un-model-cu-transformers-modulare&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Implementarea unui fișier modular&quot;,&quot;local&quot;:&quot;implementarea-unui-fișier-modular&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Config&quot;,&quot;local&quot;:&quot;config&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Norm&quot;,&quot;local&quot;:&quot;norm&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Attention&quot;,&quot;local&quot;:&quot;attention&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;DecoderLayer&quot;,&quot;local&quot;:&quot;decoderlayer&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Model&quot;,&quot;local&quot;:&quot;model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Model head&quot;,&quot;local&quot;:&quot;model-head&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Alte clase&quot;,&quot;local&quot;:&quot;alte-clase&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Finalizarea fișierului&quot;,&quot;local&quot;:&quot;finalizarea-fișierului&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Generarea fișierelor de modelare&quot;,&quot;local&quot;:&quot;generarea-fișierelor-de-modelare&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Tipare pentru fișierele modulare&quot;,&quot;local&quot;:&quot;tipare-pentru-fișierele-modulare&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Eliminarea atributelor&quot;,&quot;local&quot;:&quot;eliminarea-atributelor&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Utilizarea super()&quot;,&quot;local&quot;:&quot;utilizarea-super&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Apelarea directă a unui strămoș&quot;,&quot;local&quot;:&quot;apelarea-directă-a-unui-strămoș&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;super_kwargs&quot;,&quot;local&quot;:&quot;superkwargs&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Ștergerea metodelor neutilizate&quot;,&quot;local&quot;:&quot;ștergerea-metodelor-neutilizate&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Suprascrierea metodelor decorate&quot;,&quot;local&quot;:&quot;suprascrierea-metodelor-decorate&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Denumire specială&quot;,&quot;local&quot;:&quot;denumire-specială&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Docstring-uri pentru config&quot;,&quot;local&quot;:&quot;docstring-uri-pentru-config&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Conversia checkpoint-urilor&quot;,&quot;local&quot;:&quot;conversia-checkpoint-urilor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Scrie un script de conversie&quot;,&quot;local&quot;:&quot;scrie-un-script-de-conversie&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Maparea conversiei la runtime&quot;,&quot;local&quot;:&quot;maparea-conversiei-la-runtime&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Pașii următori&quot;,&quot;local&quot;:&quot;pașii-următori&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="adaugă-un-model-cu-transformers-modulare" 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="#adaugă-un-model-cu-transformers-modulare"><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>Adaugă un model cu transformers modulare</span></h1><!--]--><!----> <p>Transformers modulare reduce codul necesar pentru a adăuga un model, permițând importuri și moștenire, spre deosebire de politica <a href="https://huggingface.co/blog/transformers-design-philosophy" rel="nofollow">un model, un fișier</a>. În loc să repeți componentele modelului în mai multe fișiere, adaugi un fișier <em>modular</em> în folder-ul modelului și moștenește din clasele existente.</p> <p>Un convertor generează fișiere standalone din fișierul modular. Utilizatorii primesc aceeași interfață single-file cu care sunt obișnuiți.</p> <blockquote class="note"><p>Transformers modulare nu e menit să înlocuiască <a href="./add_new_model">codul de modelare legacy</a>. Dacă modelul tău nu se bazează pe un model existent, adaugă manual un fișier <code>modeling.py</code>. Același lucru se aplică fișierelor de configurare, de tokenization sau procesare care nu pot moșteni dintr-un fișier similar.</p> <p>Nu există nicio ordine unică corectă. Unii contributori scriu mai întâi fișierul modular și generează din el. Alții încep cu un fișier <code>modeling.py</code> scris manual și îl refactorizează ulterior într-un fișier modular. Ambele abordări funcționează.</p></blockquote> <!--[1--><h2 class="relative group"><a id="implementarea-unui-fișier-modular" 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="#implementarea-unui-fișier-modular"><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>Implementarea unui fișier modular</span></h2><!--]--><!----> <p>Începe prin a găsi un model în Transformers similar cu al tău. Puncte de plecare bune sunt [Mistral], [Qwen2], [Cohere], [Cohere2] și [Llama]. Tabelul de mai jos mapează componentele comune la modele din care poți moșteni.</p> <table><thead><tr><th>Componentă</th><th>Model</th></tr></thead><tbody><tr><td>Mixture of experts</td><td>Mixtral sau Qwen2-MoE</td></tr><tr><td>Interleaved (și/sau parțial) rotary embedding</td><td>GLM, Phi</td></tr><tr><td>State space models</td><td>Jamba, Bamba, Zamba, Mamba2</td></tr><tr><td>Recurrent hidden states</td><td>Gemma2</td></tr><tr><td>Sliding window attention/full attention patterns per layer</td><td>Gemma2, Cohere2</td></tr><tr><td>QKV clipping</td><td>Olmo</td></tr><tr><td>QK normalization</td><td>Olmo2, Cohere</td></tr><tr><td>Fused QKV (nu se recomandă)</td><td>Phi3</td></tr></tbody></table> <blockquote class="tip"><p>Folosește instrumentul <a href="https://huggingface.co/spaces/Molbap/modular-detector-v2" rel="nofollow">modular-detector-v2</a> pentru a găsi implementări existente din care să moștenești. Introdu un snippet de cod și îți returnează cele mai similare metode deja existente în Transformers, ca să identifici cea mai bună clasă părinte înainte să începi să scrii.</p></blockquote> <p>Nu modifica un model existent doar ca să faci moștenirea să funcționeze pentru cel nou. Dacă redenumirea sau subclasarea unei clase părinte este prea incomodă, copiază direct codul relevant.</p> <p>Creează <code>src/transformers/models/&lt;name>/modular_&lt;name>.py</code>, unde <code>&lt;name></code> corespunde numelui directorului modelului în snake_case. Această secțiune te ghidează prin implementarea [Olmo2] din [Olmo] cu abordarea modulară (consultă fișierul original <a href="../../../src/transformers/models/olmo2/modular_olmo2">modular_olmo2.py</a>).</p> <!--[2--><h3 class="relative group"><a id="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="#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>Config</span></h3><!--]--><!----> <p>Există două puncte în care <code>Olmo2Config</code> diferă de <code>OlmoConfig</code>.</p> <ol><li>Există un argument nou, <code>rms_norm_eps</code>.</li> <li>Argumentul <code>clip_qkv</code> nu mai este folosit.</li></ol> <p>Declară argumentele noi ca adnotări de tip la nivel de clasă cu o valoare implicită. Pentru argumentele eliminate, atribuie <code>AttributeError()</code> ca să suprimi atributul moștenit în fișierul generat (vezi <a href="#eliminarea-atributelor">Eliminarea atributelor</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> Copied</div><!----></button><!----></div> <pre class="language-diff "><!----><span class="hljs-deletion">- @auto_docstring(checkpoint=&quot;allenai/OLMo-7B-hf&quot;)</span>
<span class="hljs-addition">+ @auto_docstring(checkpoint=&quot;allenai/Olmo2-7B-1124-hf&quot;)</span>
<span class="hljs-addition">+ @strict</span>
<span class="hljs-deletion">- class OlmoConfig(PreTrainedConfig):</span>
<span class="hljs-addition">+ class Olmo2Config(OlmoConfig):</span>
...
<span class="hljs-deletion">- model_type = &quot;olmo&quot;</span>
<span class="hljs-addition">+ model_type = &quot;olmo2&quot;</span>
...
<span class="hljs-addition">+ rms_norm_eps: float = 1e-5</span>
<span class="hljs-deletion">- clip_qkv: float | None = None</span>
<span class="hljs-addition">+ clip_qkv = AttributeError()</span><!----></pre></div><!----> <p><code>@auto_docstring</code> generează automat documentația standard pentru argumente (vezi ghidul <a href="./auto_docstring">@auto_docstring</a>). <code>@strict</code> respinge kwargs necunoscute la momentul instanțierii, prinde greșelile de scriere și argumentele depășite din timp. Adaugă ambele la fiecare clasă de config pentru că decoratorii nu sunt moșteniți din părinte. Declară-i explicit chiar dacă config-ul părinte îi are deja.</p> <p>Pentru a seta un atribut derivat sau a gestiona logica de compatibilitate înapoi, folosește <code>__post_init__</code> în loc de <code>__init__</code>. De exemplu, Cohere2 calculează <code>head_dim</code> și derivă <code>layer_types</code> la momentul inițializării.</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 "><!----><span class="hljs-keyword">def</span> <span class="hljs-title function_">__post_init__</span>(<span class="hljs-params">self, **kwargs</span>):
<span class="hljs-keyword">if</span> <span class="hljs-variable language_">self</span>.num_key_value_heads <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
<span class="hljs-variable language_">self</span>.num_key_value_heads = <span class="hljs-variable language_">self</span>.num_attention_heads
<span class="hljs-variable language_">self</span>.head_dim = <span class="hljs-variable language_">self</span>.hidden_size // <span class="hljs-variable language_">self</span>.num_attention_heads
<span class="hljs-built_in">super</span>().__post_init__(**kwargs)<!----></pre></div><!----> <p>Pentru modelele cu suport de tensor sau pipeline parallelism, definește <code>base_model_tp_plan</code> și <code>base_model_pp_plan</code> ca dicționare la nivel de clasă pe config. Ambele dicționare definesc cum să se facă sharding-ul modelului pe dispozitive. Vezi config-urile existente precum <a href="../../../src/transformers/models/olmo2/modular_olmo2">Olmo2</a> sau <a href="../../../src/transformers/models/cohere2/modular_cohere2">Cohere2</a> pentru exemple.</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 "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">MyNewModelConfig</span>(<span class="hljs-title class_ inherited__">PreTrainedConfig</span>):
model_type = <span class="hljs-string">&quot;my_new_model&quot;</span>
<span class="hljs-comment"># Tensor parallelism: mapează pattern-uri de nume de layers la strategii de sharding.</span>
<span class="hljs-comment"># Folosește &quot;colwise&quot; / &quot;rowwise&quot; pentru sharding standard, sau variantele &quot;gather_output&quot; /</span>
<span class="hljs-comment"># &quot;split_input&quot; când o operație suplimentară (e.g. un QK norm) împiedică fuzionarea.</span>
base_model_tp_plan = {
<span class="hljs-string">&quot;layers.*.self_attn.q_proj&quot;</span>: <span class="hljs-string">&quot;colwise&quot;</span>,
<span class="hljs-string">&quot;layers.*.self_attn.k_proj&quot;</span>: <span class="hljs-string">&quot;colwise&quot;</span>,
<span class="hljs-string">&quot;layers.*.self_attn.v_proj&quot;</span>: <span class="hljs-string">&quot;colwise&quot;</span>,
<span class="hljs-string">&quot;layers.*.self_attn.o_proj&quot;</span>: <span class="hljs-string">&quot;rowwise&quot;</span>,
<span class="hljs-string">&quot;layers.*.mlp.gate_proj&quot;</span>: <span class="hljs-string">&quot;colwise&quot;</span>,
<span class="hljs-string">&quot;layers.*.mlp.up_proj&quot;</span>: <span class="hljs-string">&quot;colwise&quot;</span>,
<span class="hljs-string">&quot;layers.*.mlp.down_proj&quot;</span>: <span class="hljs-string">&quot;rowwise&quot;</span>,
}
<span class="hljs-comment"># Pipeline parallelism: mapează numele submodulelor la numele tensorilor (input, output).</span>
base_model_pp_plan = {
<span class="hljs-string">&quot;embed_tokens&quot;</span>: ([<span class="hljs-string">&quot;input_ids&quot;</span>], [<span class="hljs-string">&quot;inputs_embeds&quot;</span>]),
<span class="hljs-string">&quot;layers&quot;</span>: ([<span class="hljs-string">&quot;hidden_states&quot;</span>, <span class="hljs-string">&quot;attention_mask&quot;</span>], [<span class="hljs-string">&quot;hidden_states&quot;</span>]),
<span class="hljs-string">&quot;norm&quot;</span>: ([<span class="hljs-string">&quot;hidden_states&quot;</span>], [<span class="hljs-string">&quot;hidden_states&quot;</span>]),
}<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="norm" 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="#norm"><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>Norm</span></h3><!--]--><!----> <p>Ca să copiezi o clasă părinte fără modificări, moștenește cu <code>pass</code>. Linter-ul copiază conținutul părintelui și redenumește toate referințele să corespundă noului model.</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 "><!----><span class="hljs-keyword">from</span> ..olmo.modeling_olmo <span class="hljs-keyword">import</span> OlmoRotaryEmbedding
<span class="hljs-keyword">class</span> <span class="hljs-title class_">Olmo2RotaryEmbedding</span>(<span class="hljs-title class_ inherited__">OlmoRotaryEmbedding</span>):
<span class="hljs-keyword">pass</span><!----></pre></div><!----> <p>Ca să schimbi un comportament specific, moștenește și suprascrie doar ce diferă. <code>Olmo2RMSNorm</code> diferă de <code>LlamaRMSNorm</code> pe o singură linie. Înmulțirea se face <em>înainte</em> de a converti înapoi la input dtype, nu după.</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-diff "><!----> from ..llama.modeling_llama import LlamaRMSNorm
class Olmo2RMSNorm(LlamaRMSNorm):
def forward(self, hidden_states):
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
<span class="hljs-deletion">- return self.weight * hidden_states.to(input_dtype)</span>
<span class="hljs-addition">+ return (self.weight * hidden_states).to(input_dtype)</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="attention" 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="#attention"><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>Attention</span></h3><!--]--><!----> <p>Attention-ul lui Olmo2 este identic cu cel al lui Olmo, cu excepția că aplică <code>RMSNorm</code> la queries și keys și elimină qkv clipping. <code>super().__init__(...)</code> copiază corpul părintelui și adaugă cele două linii noi de normalizare. <code>forward</code>-ul este redefinit complet pentru că queries și keys trec acum prin norme înainte de proiecție. Linter-ul trage și orice funcții importate în fișierul generat, inclusiv <code>apply_rotary_pos_emb</code>, <code>eager_attention_forward</code> și dependecies.</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-diff "><!----> class Olmo2Attention(OlmoAttention):
def __init__(self, config: Olmo2Config, layer_idx: int | None = None):
super().__init__(config, layer_idx=layer_idx)
<span class="hljs-addition">+ self.q_norm = Olmo2RMSNorm(config.num_attention_heads * self.head_dim, config.rms_norm_eps)</span>
<span class="hljs-addition">+ self.k_norm = Olmo2RMSNorm(config.num_key_value_heads * self.head_dim, config.rms_norm_eps)</span>
def forward(self, ...):
...
<span class="hljs-deletion">- query_states = self.q_proj(hidden_states)</span>
<span class="hljs-deletion">- key_states = self.k_proj(hidden_states)</span>
<span class="hljs-addition">+ query_states = self.q_norm(self.q_proj(hidden_states))</span>
<span class="hljs-addition">+ key_states = self.k_norm(self.k_proj(hidden_states))</span>
value_states = self.v_proj(hidden_states)
<span class="hljs-deletion">- if self.config.clip_qkv is not None:</span>
<span class="hljs-deletion">- query_states.clamp_(min=-self.config.clip_qkv, max=self.config.clip_qkv)</span>
<span class="hljs-deletion">- key_states.clamp_(min=-self.config.clip_qkv, max=self.config.clip_qkv)</span>
<span class="hljs-deletion">- value_states.clamp_(min=-self.config.clip_qkv, max=self.config.clip_qkv)</span>
<span class="hljs-deletion">-</span>
...<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="decoderlayer" 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="#decoderlayer"><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>DecoderLayer</span></h3><!--]--><!----> <p>După <code>super().__init__(...)</code>, suprascrie atributele de normalizare cu instanțe <code>Olmo2RMSNorm</code> și reatribuie <code>self.self_attn</code> la noua clasă <code>Olmo2Attention</code>. <code>del self.input_layernorm</code> elimină atribuirea <code>input_layernorm</code> a părintelui deoarece Olmo2 aplică norma <em>după</em> attention, nu înainte. Vezi <a href="#eliminarea-atributelor">Eliminarea atributelor</a> pentru detalii despre ce face și ce nu face <code>del</code>.</p> <p><code>forward</code>-ul este rescris pentru a reflecta plasarea normei post-attention. O rescriere a <code>forward</code>-ului este necesară doar când un atribut este redenumit, nu când îi schimbi doar tipul.</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-diff "><!----> class Olmo2DecoderLayer(OlmoDecoderLayer):
def __init__(self, config: Olmo2Config, layer_idx: int):
super().__init__(config, layer_idx=layer_idx)
<span class="hljs-deletion">- self.self_attn = OlmoAttention(config=config, layer_idx=layer_idx)</span>
<span class="hljs-deletion">- self.input_layernorm = OlmoLayerNorm(config.hidden_size)</span>
<span class="hljs-deletion">- self.post_attention_layernorm = OlmoLayerNorm(config.hidden_size)</span>
<span class="hljs-addition">+ self.self_attn = Olmo2Attention(config=config, layer_idx=layer_idx)</span>
<span class="hljs-addition">+ del self.input_layernorm</span>
<span class="hljs-addition">+ self.post_attention_layernorm = Olmo2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)</span>
<span class="hljs-addition">+ self.post_feedforward_layernorm = Olmo2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)</span>
def forward(self, ...):
residual = hidden_states
<span class="hljs-deletion">- hidden_states = self.input_layernorm(hidden_states)</span>
# Self Attention
hidden_states, _ = self.self_attn(...)
<span class="hljs-deletion">- hidden_states = residual + hidden_states</span>
<span class="hljs-addition">+ hidden_states = self.post_attention_layernorm(hidden_states)</span>
<span class="hljs-addition">+ hidden_states = residual + hidden_states</span>
# Fully Connected
residual = hidden_states
<span class="hljs-deletion">- hidden_states = self.post_attention_layernorm(hidden_states)</span>
hidden_states = self.mlp(hidden_states)
<span class="hljs-deletion">- hidden_states = residual + hidden_states</span>
<span class="hljs-addition">+ hidden_states = self.post_feedforward_layernorm(hidden_states)</span>
<span class="hljs-addition">+ hidden_states = residual + hidden_states</span>
return hidden_states<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="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="#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>Model</span></h3><!--]--><!----> <p>Doar tipul lui <code>self.norm</code> se schimbă aici. Metoda <code>forward</code> este identică cu cea a părintelui, deci linter-ul o preia 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-diff "><!----> class Olmo2Model(OlmoModel):
def __init__(self, config: Olmo2Config):
super().__init__(config)
<span class="hljs-deletion">- self.layers = nn.ModuleList(</span>
<span class="hljs-deletion">- [OlmoDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]</span>
<span class="hljs-deletion">- )</span>
<span class="hljs-deletion">- self.norm = OlmoLayerNorm(config.hidden_size)</span>
<span class="hljs-addition">+ self.norm = Olmo2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)</span>
<span class="hljs-addition">+ self.layers = nn.ModuleList(</span>
<span class="hljs-addition">+ [Olmo2DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]</span>
<span class="hljs-addition">+ )</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="model-head" 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-head"><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>Model head</span></h3><!--]--><!----> <p>Logica este identică cu <code>OlmoForCausalLM</code>, deci nu sunt necesare modificări.</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 "><!----><span class="hljs-keyword">from</span> ..olmo.modeling_olmo <span class="hljs-keyword">import</span> OlmoForCausalLM
<span class="hljs-keyword">class</span> <span class="hljs-title class_">Olmo2ForCausalLM</span>(<span class="hljs-title class_ inherited__">OlmoForCausalLM</span>):
<span class="hljs-keyword">pass</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="alte-clase" 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="#alte-clase"><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>Alte clase</span></h3><!--]--><!----> <p>Fișierul <a href="../../../src/transformers/models/olmo2/modeling_olmo2">modeling_olmo2.py</a> generat de linter conține și clase (<code>Olmo2MLP</code>, <code>Olmo2RotaryEmbedding</code>, <code>Olmo2PreTrainedModel</code>) care nu au fost definite explicit în <code>modular_olmo2.py</code>.</p> <p>Linter-ul trage orice clasă de care depinde o clasă moștenită, dacă nu o redefinești explicit. Funcțiile importate precum <code>apply_rotary_pos_emb</code> urmează aceeași regulă.</p> <p>De exemplu, <code>OlmoDecoderLayer</code> are <code>self.mlp = OlmoMLP(config)</code>. <code>Olmo2MLP</code> n-a fost definit niciodată în fișierul modular, deci linter-ul îl creează automat, echivalent cu folosirea <code>pass</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-py "><!----><span class="hljs-keyword">from</span> ..olmo.modeling_olmo <span class="hljs-keyword">import</span> OlmoMLP
<span class="hljs-keyword">class</span> <span class="hljs-title class_">Olmo2MLP</span>(<span class="hljs-title class_ inherited__">OlmoMLP</span>):
<span class="hljs-keyword">pass</span><!----></pre></div><!----> <p>Dacă vrei ca <code>Olmo2MLP</code> să moștenească dintr-un model diferit, fii explicit.</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 "><!----><span class="hljs-comment"># trece la definiția Mistral</span>
<span class="hljs-keyword">from</span> ..mistral.modeling_mistral <span class="hljs-keyword">import</span> MistralMLP
<span class="hljs-keyword">class</span> <span class="hljs-title class_">Olmo2MLP</span>(<span class="hljs-title class_ inherited__">MistralMLP</span>):
<span class="hljs-keyword">pass</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="finalizarea-fișierului" 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="#finalizarea-fișierului"><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>Finalizarea fișierului</span></h3><!--]--><!----> <p>Fiecare fișier modular trebuie să declare un <code>logger</code> și o listă <code>__all__</code> la nivel de modul.</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 "><!---->logger = logging.get_logger(__name__)
__all__ = [
<span class="hljs-string">&quot;Olmo2Config&quot;</span>,
<span class="hljs-string">&quot;Olmo2ForCausalLM&quot;</span>,
<span class="hljs-string">&quot;Olmo2Model&quot;</span>,
<span class="hljs-string">&quot;Olmo2PreTrainedModel&quot;</span>,
]<!----></pre></div><!----> <p><code>__all__</code> trebuie să listeze fiecare clasă publică din fișier. Convertorul și importurile din aval depind de aceasta. O clasă lipsă din <code>__all__</code> nu va fi exportată corect.</p> <!--[1--><h2 class="relative group"><a id="generarea-fișierelor-de-modelare" 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="#generarea-fișierelor-de-modelare"><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>Generarea fișierelor de modelare</span></h2><!--]--><!----> <p>Script-ul <code>modular_model_converter.py</code> generează fișiere standalone <code>modeling.py</code>, <code>configuration.py</code> și altele din fișierul tău modular. Pentru fiecare clasă moștenită, copiază corpul părintelui în copil, redenumește toate referințele să corespundă noului model și trage orice funcții sau clase ajutătoare de care depind acei părinți.</p> <p>Fișierele de ieșire nu conțin importuri cross-model și nu moștenesc din alte directoare de modele. Linter-ul aplatizează moștenirea la un singur nivel. Dacă <code>Olmo2Attention</code> moștenește din <code>OlmoAttention</code>, <code>Olmo2Attention</code>-ul generat este complet autonom. Dar dacă <code>OlmoAttention</code> însuși a moștenit din altceva, linter-ul nu inlinează acel strămoș.</p> <p>Rulează comanda de mai jos pentru a genera fișiere dintr-un fișier modular.</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 "><!---->python utils/modular_model_converter.py your_model<!----></pre></div><!----> <p>Nu edita niciodată direct fișierele generate, pentru că orice modificări vor fi suprascrise la următoarea rulare.</p> <!--[1--><h2 class="relative group"><a id="tipare-pentru-fișierele-modulare" 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="#tipare-pentru-fișierele-modulare"><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>Tipare pentru fișierele modulare</span></h2><!--]--><!----> <p>Secțiunile de mai jos documentează tipare comune de utilizare, cum ar fi eliminarea atributelor sau suprascrierea metodelor decorate, când lucrezi cu un fișier modular.</p> <!--[2--><h3 class="relative group"><a id="eliminarea-atributelor" 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="#eliminarea-atributelor"><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>Eliminarea atributelor</span></h3><!--]--><!----> <p>Eliminarea unui atribut moștenit depinde de dacă lucrezi cu o clasă de config sau o subclasă <code>nn.Module</code>.</p> <p>Pentru o clasă de config, atribuie <code>AttributeError()</code> la atribut la nivel de clasă.</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 "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">MyNewConfig</span>(<span class="hljs-title class_ inherited__">ParentConfig</span>):
removed_attr = AttributeError()<!----></pre></div><!----> <p>Linter-ul elimină complet declarația atributului din fișierul de config generat. Clasele de config folosesc un layout de tip dataclass fără <code>__init__</code>, deci atribuirea <code>AttributeError()</code> la nivel de clasă este abordarea corectă.</p> <p>Pentru o subclasă <code>nn.Module</code>, folosește <code>del self.attribute</code> după <code>super().__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-py "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">MyNewModel</span>(<span class="hljs-title class_ inherited__">ParentModel</span>):
<span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, config: MyNewConfig</span>):
<span class="hljs-built_in">super</span>().__init__(config)
<span class="hljs-keyword">del</span> <span class="hljs-variable language_">self</span>.attribute<!----></pre></div><!----> <p><code>del self.attribute</code> elimină doar linia de atribuire <code>self.attribute = ...</code> din corpul copiat al părintelui. Nu elimină alte linii care fac referire la <code>self.attribute</code>. Dacă <code>forward</code>-ul părintelui sau alte metode fac referire la atribut, suprascrie și acele 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-py "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">DummyModel</span>(nn.Module):
<span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, config: DummyConfig</span>):
<span class="hljs-built_in">super</span>().__init__()
<span class="hljs-variable language_">self</span>.attribute = config.attribute
<span class="hljs-keyword">if</span> <span class="hljs-variable language_">self</span>.attribute:
<span class="hljs-comment"># fă mai multe lucruri cu `self.attribute` aici</span>
...
<span class="hljs-keyword">class</span> <span class="hljs-title class_">MyNewDummyModel</span>(<span class="hljs-title class_ inherited__">DummyModel</span>):
<span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, config: MyNewDummyConfig</span>):
<span class="hljs-built_in">super</span>().__init__(config)
<span class="hljs-keyword">del</span> <span class="hljs-variable language_">self</span>.attribute
<span class="hljs-comment"># &#x27;self.attribute = config.attribute&#x27; este eliminat, dar blocul &#x27;if self.attribute:&#x27; rămâne.</span>
<span class="hljs-comment"># Suprascrie forward() sau orice altă metodă care face referire la self.attribute.</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="utilizarea-super" 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="#utilizarea-super"><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>Utilizarea super()</span></h3><!--]--><!----> <p><code>super().__init__(config)</code> îi spune convertorului să copieze corpul părintelui în copil. Două tipare îți permit să suprascrii acest comportament.</p> <ul><li>Apelează direct o clasă părinte specifică când ai nevoie ca ieșirea generată să apeleze un strămoș (<code>nn.Module.__init__</code>) în loc de părintele modular.</li> <li>Folosește <code>**super_kwargs</code> pentru a moșteni semnătura completă a metodei unui părinte, adăugând în același timp un docstring personalizat sau schimbând un decorator.</li></ul> <!--[3--><h4 class="relative group"><a id="apelarea-directă-a-unui-strămoș" 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="#apelarea-directă-a-unui-strămoș"><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>Apelarea directă a unui strămoș</span></h4><!--]--><!----> <p>Fii explicit despre ce clasă apelezi când ai nevoie ca <code>super()</code> să țintească părintele clasei generate în loc de părintele modular. Exemplul de mai jos apelează direct <code>nn.Module.__init__(self)</code>. <code>DummyModule</code> este el însuși un <code>nn.Module</code>, deci convertorul îl scrie ca <code>super().__init__()</code> în <code>MyNewDummyModule</code>-ul generat.</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 "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">MyNewDummyModule</span>(<span class="hljs-title class_ inherited__">DummyModule</span>): | <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyNewDummyModule</span>(nn.Module):
|
<span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self</span>): | <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self</span>):
nn.Module.__init__(<span class="hljs-variable language_">self</span>) | <span class="hljs-built_in">super</span>().__init__()
<span class="hljs-variable language_">self</span>.foo = config.foo | <span class="hljs-variable language_">self</span>.foo = config.foo
... | ...<!----></pre></div><!----> <!--[3--><h4 class="relative group"><a id="superkwargs" 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="#superkwargs"><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>super_kwargs</span></h4><!--]--><!----> <p>Folosește <code>**super_kwargs</code> pentru a moșteni semnătura completă a metodei unui părinte, adăugând în același timp un docstring personalizat sau schimbând un decorator. În semnătura suprascrisă, îi spune linter-ului să expandeze toate argumentele părintelui în ieșirea generată.</p> <p>Cel mai comun use case este adăugarea unui docstring specific modelului, cum ar fi documentarea argumentului <code>labels</code>, fără a rescrie semnătura completă.</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 "><!----><span class="hljs-comment"># modular_gemma.py</span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">GemmaForCausalLM</span>(<span class="hljs-title class_ inherited__">LlamaForCausalLM</span>):
<span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">**super_kwargs</span>):
<span class="hljs-string">r&quot;&quot;&quot;
Example:
```python
&gt;&gt;&gt; from transformers import AutoTokenizer, GemmaForCausalLM
&gt;&gt;&gt; model = GemmaForCausalLM.from_pretrained(&quot;google/gemma-7b&quot;)
...
```&quot;&quot;&quot;</span>
<span class="hljs-keyword">return</span> <span class="hljs-built_in">super</span>().forward(**super_kwargs)<!----></pre></div><!----> <p><code>GemmaForCausalLM.forward</code>-ul generat are semnătura completă a lui <code>LlamaForCausalLM</code> fără copiere manuală.</p> <p><code>**super_kwargs</code> este o scurtătură pentru cazuri de nișă. Dacă schimbi comportamentul, scrie semnătura completă.</p> <!--[2--><h3 class="relative group"><a id="ștergerea-metodelor-neutilizate" 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="#ștergerea-metodelor-neutilizate"><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>Ștergerea metodelor neutilizate</span></h3><!--]--><!----> <p>Elimină o metodă a părintelui suprascriind-o cu o instrucțiune <code>raise AttributeError("")</code>. Linter-ul elimină metoda din fișierul generat.</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 "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">GemmaTokenizer</span>(<span class="hljs-title class_ inherited__">LlamaTokenizer</span>):
...
<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_spm_processor</span>(<span class="hljs-params">self</span>):
<span class="hljs-keyword">raise</span> AttributeError(<span class="hljs-string">&quot;Not needed for Gemma&quot;</span>)
<span class="hljs-keyword">def</span> <span class="hljs-title function_">unk_token_length</span>(<span class="hljs-params">self</span>):
<span class="hljs-keyword">raise</span> AttributeError(<span class="hljs-string">&quot;Not needed for Gemma&quot;</span>)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="suprascrierea-metodelor-decorate" 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="#suprascrierea-metodelor-decorate"><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>Suprascrierea metodelor decorate</span></h3><!--]--><!----> <p>Când suprascrieți o metodă decorată a părintelui, decoratorul părintelui se transferă automat. Dacă adaugi propriul decorator, acesta îl înlocuiește pe cel al părintelui.</p> <p>Două decoratoare apar frecvent în librărie: unul pentru <a href="./model_output_tracing">capturarea ieșirilor intermediare ale modelului</a> și unul pentru <a href="./auto_docstring">auto-generarea docstring-urilor</a>.</p> <p>În exemplul de mai jos, o subclasă suprascrie o metodă decorată a părintelui fără a adăuga propriul decorator. Decoratorul părintelui se transferă.</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 "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">NewModel</span>(<span class="hljs-title class_ inherited__">DummyModel</span>): | <span class="hljs-keyword">class</span> <span class="hljs-title class_">NewModel</span>(nn.Module):
... | ...
|
<span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">...</span>): | @decorator(...)
... | <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">...</span>):
| ...<!----></pre></div><!----> <p>Dacă adaugi un decorator nou, decoratorul tău îl înlocuiește pe cel al părintelui.</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 "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">NewModel</span>(<span class="hljs-title class_ inherited__">DummyModel</span>): | <span class="hljs-keyword">class</span> <span class="hljs-title class_">NewModel</span>(nn.Module):
... | ...
|
<span class="hljs-meta"> @my_new_decorator(<span class="hljs-params">...</span>) | @my_new_decorator(<span class="hljs-params">...</span>)</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">...</span>): | <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">...</span>):
... | ...<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="denumire-specială" 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="#denumire-specială"><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>Denumire specială</span></h3><!--]--><!----> <p>Linter-ul redenumește automat totul când moștenești dintr-o clasă. Folosește același prefix de nume de clasă în toate clasele din același fișier.</p> <p>Evită amestecarea prefixelor ca în exemplul de mai jos. <code>MyModelIncredibleMLP</code> încalcă convențiile de denumire și linter-ul nu va ști dacă să folosească <code>MyModelIncredible</code> sau <code>MyModel</code> la redenumirea dependențelor de ordin superior.</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 "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModelIncredibleMLP</span>(<span class="hljs-title class_ inherited__">LlamaMLP</span>):
...
<span class="hljs-keyword">class</span> <span class="hljs-title class_">MyModelDecoderLayer</span>(<span class="hljs-title class_ inherited__">LlamaDecoderLayer</span>):
...<!----></pre></div><!----> <p>Fără <a href="#alte-clase">dependențe implicite</a>, poți redenumi o singură clasă local. Redefinește explicit fiecare altă mențiune a acelei clase cu noul tipar de nume. Altfel, linter-ul adaugă o clasă <code>MyModelMLP</code> nedorită alături de <code>MyModelIncredibleMLP</code>.</p> <p>Linter-ul ridică un avertisment când detectează un prefix ambiguu.</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-text "><!---->We detected multiple prefix names when inheriting from transformers.models.llama.modeling_llama: (&#x27;Emu3Text&#x27;, &#x27;Emu3&#x27;). We will only use the most used &#x27;Emu3&#x27; prefix when grabbing args and dependencies. Make sure to subclass the intermediate classes with the prefix you want (if different from &#x27;Emu3&#x27;) or use a single prefix in all the modular (best).<!----></pre></div><!----> <p>Prefixele ambigue sunt cele mai comune în modelele multimodale unde numele claselor includ un calificativ de modalitate precum <code>Text</code>. Ca să dai unei dependențe un prefix specific, redenumește-o explicit cu un <code>pass</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-py "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">Emu3TextMLP</span>(<span class="hljs-title class_ inherited__">LlamaMLP</span>):
<span class="hljs-keyword">pass</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="docstring-uri-pentru-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="#docstring-uri-pentru-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>Docstring-uri pentru config</span></h3><!--]--><!----> <p>Linter-ul nu suportă încă moștenirea parțială a docstring-urilor. Când adaugi sau elimini atribute de config, adaugă docstring-ul complet direct în fișierul modular sub definiția clasei.</p> <!--[1--><h2 class="relative group"><a id="conversia-checkpoint-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="#conversia-checkpoint-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>Conversia checkpoint-urilor</span></h2><!--]--><!----> <p>Odată ce ai generat fișierele de modelare, verifică că weights-urile reale se încarcă corect. Scrie un script de conversie pentru a traduce formatul checkpoint-ului upstream într-unul compatibil cu Transformers, apoi salvează-l pe Hub.</p> <!--[2--><h3 class="relative group"><a id="scrie-un-script-de-conversie" 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="#scrie-un-script-de-conversie"><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>Scrie un script de conversie</span></h3><!--]--><!----> <p>Adaugă un fișier <code>convert_&lt;model>_to_hf.py</code> în <code>src/transformers/models/&lt;model>/</code>. Scriptul încarcă weights-urile upstream, redenumește și remodelează cheile să corespundă numelor parametrilor modulului tău și salvează rezultatul cu <code>save_pretrained()</code>.</p> <blockquote class="tip"><p>Caută un script existent pe care să îl copiezi și adaptezi. Modelele din <code>src/transformers/models/</code> includ un <code>convert_*_to_hf.py</code> pe care îl poți folosi ca punct de plecare.</p></blockquote> <p>După rularea scriptului, încarcă checkpoint-ul salvat cu <code>from_pretrained()</code> și confirmă că fiecare weight s-a încărcat corect. Cheile de checkpoint neutilizate indică nume nepotrivite, deci printează-le ca să detectezi problemele din timp.</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 "><!---->model = YourModelForTask.from_pretrained(<span class="hljs-string">&quot;path/to/output/&quot;</span>)<!----></pre></div><!----> <p>Verifică potrivirile de formă și nume când iterezi peste chei. Nepotrivirile de formă indică de obicei că un parametru din config este greșit, că arhitectura diferă de cea originală sau că un weight trebuie transpus.</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 "><!----><span class="hljs-keyword">for</span> key, tensor <span class="hljs-keyword">in</span> original_state_dict.items():
hf_tensor = hf_model.state_dict().get(mapped_key)
<span class="hljs-keyword">assert</span> hf_tensor.shape == tensor.shape, (
<span class="hljs-string">f&quot;Shape mismatch for <span class="hljs-subst">{key}</span>: expected <span class="hljs-subst">{tensor.shape}</span>, got <span class="hljs-subst">{hf_tensor.shape}</span>&quot;</span>
)<!----></pre></div><!----> <p>Rezolvă orice problemă iterând între fișierul modular, fișierul de modelare generat și scriptul de conversie până când toate weights-urile se încarcă curat.</p> <p>Odată ce checkpoint-ul se încarcă curat, publicați-l pe Hub cu <code>push_to_hub()</code>. Consultă ghidul <a href="./model_sharing">distribuirea modelelor</a> pentru mai multe detalii.</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 "><!---->model.push_to_hub(<span class="hljs-string">&quot;username/your-model-name&quot;</span>)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="maparea-conversiei-la-runtime" 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="#maparea-conversiei-la-runtime"><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>Maparea conversiei la runtime</span></h3><!--]--><!----> <p>Adaugă o mapare runtime în <code>src/transformers/conversion_mapping.py</code> când weights publicate nu corespund layout-ului de parametri al modulului tău. Cazurile comune includ weights fuzionate stocate separat și tensorii de experți MoE care trebuie stivuiți. Maparea permite ca <code>from_pretrained()</code> să încarce checkpoint-ul de pe Hub fără un pas de export separat.</p> <p>Consultă ghidul <a href="./weightconverter">încărcarea dinamică de weights</a> pentru cum să scrii reguli <code>WeightRenaming</code> și <code>WeightConverter</code> și să le înregistrezi pentru <code>model_type</code>-ul tău.</p> <!--[1--><h2 class="relative group"><a id="pașii-următori" 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="#pașii-următori"><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>Pașii următori</span></h2><!--]--><!----> <ul><li><a href="./modeling_rules">Regulile de structură a modelului</a> sunt reguli statice aplicate pe toate fișierele <code>modeling_*.py</code>, <code>modular_*.py</code> și <code>configuration_*.py</code>. Rulează <code>make typing</code> să le verifici înainte de a deschide un PR.</li> <li><a href="./add_vision_processing_components">Adaugă componente de procesare vizuală</a> te ghidează prin adăugarea unui procesor de imagini, procesor video și procesor pentru un model multimodal.</li> <li><a href="./auto_docstring">Auto-generarea docstring-urilor</a> arată cum să folosești <code>@auto_docstring</code> ca să nu scrii manual documentația pentru argumente la API-uri comune.</li> <li><a href="./testing">Scrierea testelor pentru modele</a> acoperă cum să scrii teste de integrare pentru noul tău model și să le rulezi local.</li> <li><a href="./pr_checks">Verificările pentru pull request</a> explică verificările CI pe care PR-ul tău trebuie să le treacă înainte de a fi integrat și cum să le reproduci și rezolvi local.</li></ul> <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/modular_transformers.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_1pz8pps = {
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.CIgIKwFw.js"),
import("/docs/transformers/main/ro/_app/immutable/entry/app.eNKDC4Vf.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 22],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
107 kB
·
Xet hash:
934f7a4757f2b854460fa5701b7f7cc284105d803ea4bdb95d65716bd5946bf8

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