Buckets:

hf-doc-build/doc / transformers /main /fr /perf_infer_gpu_multi.html
mishig's picture
download
raw
66.9 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Parallélisme de tenseurs pour l'inférence&quot;,&quot;local&quot;:&quot;tensor-parallelism-for-inference&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Partitionnement d'un modèle&quot;,&quot;local&quot;:&quot;partitioning-a-model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Stratégies de partitionnement&quot;,&quot;local&quot;:&quot;partitioning-strategies&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Stratégies compactes&quot;,&quot;local&quot;:&quot;packed-strategies&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Stratégies de partitionnement personnalisées&quot;,&quot;local&quot;:&quot;custom-partitioning-strategies&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Benchmarks&quot;,&quot;local&quot;:&quot;benchmarks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Implémentation de la conception&quot;,&quot;local&quot;:&quot;design-implementation&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;DeviceMesh&quot;,&quot;local&quot;:&quot;devicemesh&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;DTensor&quot;,&quot;local&quot;:&quot;dtensor&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Ressources&quot;,&quot;local&quot;:&quot;resources&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/transformers/main/en/_app/immutable/entry/start.DGrKXpv6.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/DoZUvFUu.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/BsjdiN7w.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/entry/app.-AoMVxrm.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/BH1X_C60.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/DOLBYqcr.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/CP4atVuv.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/nodes/0.TL5ohTJT.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/DFlXo4oz.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/nodes/5.BtD--kzE.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/BtP4ra3h.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/DQb2T5S_.js" rel="modulepreload">
<!--1skuau8--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Tensor parallelism for inference&quot;,&quot;local&quot;:&quot;tensor-parallelism-for-inference&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Partitioning a model&quot;,&quot;local&quot;:&quot;partitioning-a-model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Partitioning strategies&quot;,&quot;local&quot;:&quot;partitioning-strategies&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Packed strategies&quot;,&quot;local&quot;:&quot;packed-strategies&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Custom partitioning strategies&quot;,&quot;local&quot;:&quot;custom-partitioning-strategies&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Benchmarks&quot;,&quot;local&quot;:&quot;benchmarks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Design implementation&quot;,&quot;local&quot;:&quot;design-implementation&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;DeviceMesh&quot;,&quot;local&quot;:&quot;devicemesh&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;DTensor&quot;,&quot;local&quot;:&quot;dtensor&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Resources&quot;,&quot;local&quot;:&quot;resources&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/transformers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="tensor-parallelism-for-inference" 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="#tensor-parallelism-for-inference"><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><!---->Parallélisme de tenseurs pour l'inférence<!----></span></h1><!--]--><!----> <p><a href="./perf_train_gpu_many#tensor-parallelism">Le parallélisme de tenseurs</a> découpe une couche de modèle en plusieurs morceaux afin que plusieurs accélérateurs matériels puissent y travailler simultanément. Cela permet d'exécuter des modèles dont la taille dépasse la capacité mémoire d'un seul GPU et d'atteindre un débit supérieur. Une communication intra-nœud rapide est nécessaire, car les GPU échangent des résultats partiels à chaque couche.</p> <p>Un modèle prend en charge le parallélisme de tenseurs si sa configuration définit <code>base_model_tp_plan</code>. Vérifiez un modèle chargé à l'aide de la propriété <code>supports_tp_plan</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;meta-llama/Meta-Llama-3-8B-Instruct&quot;</span>)
<span class="hljs-built_in">print</span>(model.supports_tp_plan)<!----></pre></div><!----> <p>Ce guide explique comment activer le parallélisme de tenseurs dans Transformers et les stratégies de partitionnement disponibles.</p> <!--[1--><h2 class="relative group"><a id="partitioning-a-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="#partitioning-a-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><!---->Partitionnement d'un modèle<!----></span></h2><!--]--><!----> <p>Configurez le nombre d’appareils de parallélisme de tenseurs avec <code>tp_size</code> dans <a href="/docs/transformers/main/fr/expert_parallelism#transformers.DistributedConfig">DistributedConfig</a>.</p> <ul><li>Définissez <code>DistributedConfig(tp_size=N)</code> pour utiliser le plan prédéfini du modèle.</li> <li>Définissez un <code>tp_plan</code> manuel et transmettez-le à <a href="/docs/transformers/main/fr/expert_parallelism#transformers.DistributedConfig">DistributedConfig</a> avec <code>tp_size</code>.</li></ul> <p>Vous pouvez également définir <code>tp_plan="auto"</code> pour demander explicitement le plan prédéfini. Lorsque <code>tp_size</code> est omis et qu'un <code>tp_plan</code> est défini, <code>tp_size</code> est dérivé de <code>WORLD_SIZE</code> divisé par les autres tailles de parallélisme. Transmettre <code>tp_plan</code> directement à <a href="/docs/transformers/main/fr/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> est déprécié et sera supprimé dans la v5.18.</p> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><!--[--><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">plan auto</div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">plan manuel</div><!--]--></div> <div class="language-select"><div><div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer, DistributedConfig
<span class="hljs-comment"># model_id = &quot;meta-llama/Llama-4-Scout-17B-16E-Instruct&quot; # better to visualize all the possible strategies</span>
distributed_config = DistributedConfig(tp_size=<span class="hljs-number">4</span>)
model = AutoModelForCausalLM.from_pretrained(
<span class="hljs-string">&quot;meta-llama/Meta-Llama-3-8B-Instruct&quot;</span>,
dtype=torch.bfloat16,
distributed_config=distributed_config,
)
<span class="hljs-built_in">print</span>(model.tp_plan)
tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;meta-llama/Meta-Llama-3-8B-Instruct&quot;</span>)
prompt = <span class="hljs-string">&quot;Can I help&quot;</span>
inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids.to(model.device)
<span class="hljs-comment"># distributed run</span>
outputs = model(inputs)<!----></pre></div><!----> <p>Lancez le script d’inférence avec <a href="https://pytorch.org/docs/stable/elastic/run.html" rel="nofollow">torchrun</a>. Utilisez un processus par GPU.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-bash "><!---->torchrun --nproc-per-node 4 demo.py<!----></pre></div><!----><!----></div><!----> <div hidden=""><p>Définissez un plan de parallélisme tensoriel pour chaque couche dans <code>tp_plan</code> et transmettez-le via <a href="/docs/transformers/main/fr/expert_parallelism#transformers.DistributedConfig">DistributedConfig</a>. L’exemple ci-dessous utilise le partitionnement par colonnes et par lignes. Consultez la section <a href="#partitioning-strategies">Stratégies de partitionnement</a> pour les autres stratégies prises en charge.</p> <p>Le partitionnement manuel exige une compréhension approfondie de l’architecture du modèle et des interactions entre les stratégies. De mauvais choix de partitionnement aboutissent à des modèles lents qui échouent ou produisent des résultats incorrects. Le <a href="https://huggingface.co/spaces/nanotron/ultrascale-playbook?section=tensor_parallelism" rel="nofollow">Ultra-Scale Playbook</a> détaille les stratégies de partitionnement.</p> <p>Les clés sont des noms de modules ou de paramètres, où <code>*</code> représente les indices de couches. Un nom de stratégie non reconnu déclenche une <code>ValueError</code> listant les noms pris en charge, et Transformers journalise un avertissement pour les règles de plan qui n’ont rien correspondu et pour les paramètres non couverts par aucune règle.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, DistributedConfig
tp_plan = {
<span class="hljs-string">&quot;model.layers.*.self_attn.q_proj&quot;</span>: <span class="hljs-string">&quot;colwise&quot;</span>,
<span class="hljs-string">&quot;model.layers.*.self_attn.k_proj&quot;</span>: <span class="hljs-string">&quot;colwise&quot;</span>,
<span class="hljs-string">&quot;model.layers.*.self_attn.v_proj&quot;</span>: <span class="hljs-string">&quot;colwise&quot;</span>,
<span class="hljs-string">&quot;model.layers.*.self_attn.o_proj&quot;</span>: <span class="hljs-string">&quot;rowwise&quot;</span>,
...
}
distributed_config = DistributedConfig(tp_size=<span class="hljs-number">4</span>, tp_plan=tp_plan)
model = AutoModelForCausalLM.from_pretrained(
<span class="hljs-string">&quot;meta-llama/Meta-Llama-3-8B-Instruct&quot;</span>,
dtype=<span class="hljs-string">&quot;auto&quot;</span>,
distributed_config=distributed_config,
)
<span class="hljs-built_in">print</span>(model.tp_plan)<!----></pre></div><!----><!----></div><!----><!----></div><!----> <!--[1--><h2 class="relative group"><a id="partitioning-strategies" 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="#partitioning-strategies"><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><!---->Stratégies de partitionnement<!----></span></h2><!--]--><!----> <p><code>ALL_PARALLEL_STYLES</code>, une <code>ParallelInterface</code> définie dans <a href="https://github.com/huggingface/transformers/blob/main/src/transformers/distributed/parallel_utils.py" rel="nofollow">distributed/parallel_utils.py</a>, associe chaque nom de stratégie utilisable dans un plan à une instance de stratégie configurée. Vous n’interagissez pas directement avec elle pour sharder un modèle, mais elle constitue la liste officielle des noms disponibles. <a href="https://github.com/huggingface/transformers/blob/main/src/transformers/distributed/tensor_parallel.py" rel="nofollow">distributed/tensor_parallel.py</a> y enregistre les stratégies de parallélisme tensoriel :</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-py "><!---->ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;embedding_rowwise&quot;</span>, EmbeddingParallel(shard_dim=<span class="hljs-number">0</span>))
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;embedding_colwise&quot;</span>, EmbeddingParallel(shard_dim=<span class="hljs-number">1</span>))
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;colwise_gather_output&quot;</span>, ColwiseParallel(input_layouts=Replicate(), output_layouts=Replicate()))
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;colwise_rep&quot;</span>, ColwiseParallel(input_layouts=Replicate(), output_layouts=Replicate()))
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;colwise&quot;</span>, ColwiseParallel(input_layouts=Replicate(), output_layouts=Shard(-<span class="hljs-number">1</span>)))
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;rowwise&quot;</span>, RowwiseParallel(input_layouts=Shard(-<span class="hljs-number">1</span>), output_layouts=Replicate()))
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;rowwise_split_input&quot;</span>, RowwiseParallel(input_layouts=Replicate(), output_layouts=Replicate()))
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;rowwise_rep&quot;</span>, RowwiseParallel(input_layouts=Replicate(), output_layouts=Replicate()))
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;packed_colwise&quot;</span>, PackedColwiseParallel())
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;packed_rowwise&quot;</span>, PackedRowwiseParallel())
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;sequence_parallel&quot;</span>, SequenceParallel(use_local_output=<span class="hljs-literal">True</span>))
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;replicated_with_grad_allreduce&quot;</span>, ReplicatedWithGradAllReduce())
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;mla_kv_a_proj&quot;</span>, MlaKvAProjParallel())
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;all_reduce&quot;</span>, AllReduceParallel())
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;moe_tp_experts&quot;</span>, MoeExpertsParallel())
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;moe_identity_expert&quot;</span>, MoeIdentityParallel())
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;local_params&quot;</span>, LocalParamsParallel())<!----></pre></div><!----> <p>Chaque stratégie de parallélisme tensoriel est une sous-classe de <code>TensorParallelLayer</code> dans ce fichier. Les stratégies de parallélisme d'experts, telles que <code>ep_dispatch_experts</code>, se trouvent dans <a href="https://github.com/huggingface/transformers/blob/main/src/transformers/distributed/expert_parallel.py" rel="nofollow">distributed/expert_parallel.py</a>, héritent de <code>ExpertParallelLayer</code>, qui possède les mêmes hooks, et s'enregistrent dans le même <code>ALL_PARALLEL_STYLES</code>. Les deux que vous utiliserez le plus souvent, <code>ColwiseParallel</code> et <code>RowwiseParallel</code>, prennent des placements <code>input_layouts</code> et <code>output_layouts</code>, ce qui permet à une seule classe de couvrir plusieurs noms de plans. <code>colwise</code> laisse sa sortie fragmentée sur la dernière dimension pour qu'une couche <code>rowwise</code> suivante puisse la consommer, tandis que <code>colwise_gather_output</code> la réassemble en un tenseur complet via un all-gather.</p> <p>Le tableau ci-dessous décrit chaque stratégie.</p> <table><thead><tr><th>Stratégie</th><th>Description</th></tr></thead><tbody><tr><td><code>ColwiseParallel</code></td><td>Fragmente un poids linéaire sur sa dimension de caractéristiques de sortie (<code>Shard(0)</code> pour un poids <code>nn.Linear</code> 2D) et fragmente un biais 1D. Redistribue l'entrée vers <code>Replicate()</code>, puis place la sortie dans <code>output_layouts</code>.</td></tr><tr><td><code>RowwiseParallel</code></td><td>Fractionne le poids linéaire sur sa dimension de fonction d’entrée (<code>Shard(-1)</code>) et réplique le biais, qui est ajouté après la réduction. Le forward de chaque rang produit une sortie <code>Partial()</code> contenant sa part de la somme, et <code>transform_output_post_forward</code> la redistribue vers <code>output_layouts</code>. Réduire vers <code>Replicate()</code> déclenche un all-reduce, et réduire vers <code>Shard(1)</code> déclenche un reduce-scatter.</td></tr><tr><td><code>EmbeddingParallel</code></td><td>Fragmente un <code>nn.Embedding</code> en répliquant les identifiants de jetons. <code>shard_dim=0</code> (<code>embedding_rowwise</code>, le choix habituel) fragmente le vocabulaire et effectue une réduction globale (all-reduce) des résultats partiels de chaque rang pour obtenir la sortie complète. <code>shard_dim=1</code> (<code>embedding_colwise</code>) fragmente la dimension cachée et effectue une collecte globale (all-gather) des tranches de sortie de chaque rang.</td></tr><tr><td><code>PackedColwiseParallel</code></td><td>Une variante de <code>ColwiseParallel</code> pour les poids fusionnés, par exemple <code>up_proj</code> et <code>gate_proj</code> regroupés dans <code>gate_up_proj</code>. Utilisez <code>split_factor</code> lorsqu'un poids regroupe un nombre de couches différent de deux.</td></tr><tr><td><code>PackedRowwiseParallel</code></td><td>L'équivalent par ligne, pour les poids empilés le long de la dernière dimension. Réplique les paramètres 1D.</td></tr><tr><td><code>SequenceParallel</code></td><td>Duplique les paramètres du module et sharde son entrée sur <code>sequence_dim</code> (par défaut <code>1</code>). Utilisé pour les normalisations qui opèrent par jeton, telles que <code>LayerNorm</code> et <code>RMSNorm</code>.</td></tr><tr><td><code>ReplicatedWithGradAllReduce</code></td><td>Duplique un paramètre mais effectue un all-reduce sur son gradient. Nécessaire pour les normes situées entre une couche en colonnes et une couche en lignes, qui normalisent le long d'un axe fragmenté, où chaque rang ne voit que ses propres têtes.</td></tr><tr><td><code>AllReduceParallel</code></td><td>Effectue une réduction globale (all-reduce) de la sortie avant <code>Partial()</code> d'un module vers <code>Replicate()</code>. Utilisez-le comme point de synchronisation pour un module dont le calcul se termine par une somme partielle.</td></tr><tr><td><code>MlaKvAProjParallel</code></td><td>Découpe la sortie de <code>kv_a_proj_with_mqa</code> de l'attention MLA de type DeepSeek-V2 et effectue un all-reduce sur le gradient de la moitié RoPE, ce qui contourne <code>kv_b_proj</code> et éviterait sinon de conserver un gradient partiel. Nécessite <code>qk_rope_head_dim</code> dans la configuration du modèle.</td></tr><tr><td><code>MoeExpertsParallel</code></td><td>Experts MoE en parallélisme de tenseurs. Effectue un all-reduce sur la sortie avant des experts et ajoute les all-reduces de rétropropagation pour les états cachés et les poids de routage.</td></tr><tr><td><code>MoeIdentityParallel</code></td><td>Divise par avance l’entrée d’un expert nul ou identité par la taille du maillage, annulant ainsi l’opération all-reduce appliquée en aval par <code>moe_tp_experts</code>.</td></tr><tr><td><code>LocalParamsParallel</code></td><td>Exécute le forward d’un module avec ses propres paramètres shardés en tant que tenseurs locaux. À utiliser sur le propriétaire d’un <code>nn.Parameter</code> brut, tel que les attention sinks, que sa propre entrée de plan sharde.</td></tr><tr><td><code>MoEParamShard</code></td><td>Répartit les poids des experts MoE sur un placement donné. Soutient le nom <code>grouped_gemm</code>, où <code>shards_expert_dim=True</code> réécrit également <code>module.num_experts</code> en le nombre d'experts par rang.</td></tr></tbody></table> <!--[2--><h3 class="relative group"><a id="packed-strategies" 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="#packed-strategies"><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><!---->Stratégies compactes<!----></span></h3><!--]--><!----> <p>Le regroupement de poids combine plusieurs couches linéaires en une seule couche plus grande. Les stratégies <code>PackedColwiseParallel</code> et <code>PackedRowwiseParallel</code> fractionnent correctement les poids regroupés. Les stratégies de base <code>ColwiseParallel</code> ou <code>RowwiseParallel</code> fractionnent incorrectement les poids regroupés.</p> <p>L’exemple ci-dessous regroupe <code>up_proj</code> et <code>gate_proj</code> en un seul module <code>gate_up_proj</code> et requiert la stratégie <code>packed_rowwise</code> pour sharder <code>gate_up_proj</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">Llama4TextExperts</span>(nn.Module):
...
<span class="hljs-variable language_">self</span>.gate_up_proj = nn.Parameter(torch.zeros(<span class="hljs-variable language_">self</span>.num_experts, <span class="hljs-variable language_">self</span>.hidden_size, <span class="hljs-number">2</span> * <span class="hljs-variable language_">self</span>.expert_dim))<!----></pre></div><!----> <p>Utilisez la multiplication matricielle par lots dans le passage <code>forward</code> pour calculer la sortie du module <code>gate_up_proj</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, hidden_states</span>):
...
gate_up = torch.bmm(hidden_states, <span class="hljs-variable language_">self</span>.gate_up_proj) <span class="hljs-comment"># Compute the output of the gate_up_proj module</span>
gate, up = gate_up.chunk(<span class="hljs-number">2</span>, dim=-<span class="hljs-number">1</span>) <span class="hljs-comment"># Split the output into gate and up</span><!----></pre></div><!----> <p>Un <code>Shard</code> simple divise cette dimension en blocs contigus, de sorte qu'un rang reçoit la fin de <code>gate</code> et le début de <code>up</code> au lieu d'une tranche de chacun. Les stratégies empilées utilisent <code>_StridedShard</code> avec <code>split_factor</code> (<code>2</code> par défaut) pour entrelacer la division, ce qui donne à chaque rang une tranche correspondante des deux moitiés afin que <code>chunk</code> reste aligné après le sharding.</p> <!--[1--><h2 class="relative group"><a id="custom-partitioning-strategies" 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="#custom-partitioning-strategies"><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><!---->Stratégies de partitionnement personnalisées<!----></span></h2><!--]--><!----> <p>Hériter de <code>TensorParallelLayer</code> dans <a href="https://github.com/huggingface/transformers/blob/main/src/transformers/distributed/tensor_parallel.py" rel="nofollow">distributed/tensor_parallel.py</a> pour créer une stratégie de partitionnement personnalisée. N’implémenter que les hooks dont votre stratégie a besoin, car chacun d’entre eux possède un comportement par défaut sans effet.</p> <table><thead><tr><th>Hook</th><th>Objectif</th></tr></thead><tbody><tr><td><code>validate_param</code></td><td>Rejeter un paramètre que cette stratégie ne peut pas fractionner, avant le chargement de tout poids.</td></tr><tr><td><code>shard_param</code></td><td>Remplacez un paramètre par un espace réservé <code>DTensor</code> afin que le chargeur sache quelle partition appartient à ce rang.</td></tr><tr><td><code>transform_inputs_pre_forward</code></td><td>Redistribuer les entrées du module vers la disposition attendue par son forward.</td></tr><tr><td><code>context_around_forward</code></td><td>Enveloppez le forward dans un gestionnaire de contexte, par exemple pour exposer des tenseurs locaux à un noyau.</td></tr><tr><td><code>transform_output_post_forward</code></td><td>Redistribuer ou réduire la sortie du module.</td></tr><tr><td><code>should_use_local_tensors</code></td><td>Signalez que la méthode forward de ce module nécessite des tenseurs simples plutôt que des <code>DTensor</code>.</td></tr><tr><td><code>install_forward</code></td><td>Remplacez <code>module.forward</code> en totalité. N’implémentez cette méthode que si les hooks ci-dessus ne suffisent pas, comme le fait <code>ReplicatedWithGradAllReduce</code> pour enregistrer un hook de rétropropagation.</td></tr></tbody></table> <p>L'exemple ci-dessous détaille une version simplifiée de <code>ColwiseParallel</code>.</p> <ol><li><p>Hériter de <code>TensorParallelLayer</code> et stocker les placements avec lesquels la stratégie fonctionne. La classe de base ne définit pas de <code>__init__</code>, il n’y a donc rien sur lequel appeler <code>super()</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">class</span> <span class="hljs-title class_">ColwiseParallel</span>(<span class="hljs-title class_ inherited__">TensorParallelLayer</span>):
<span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, *, input_layouts=<span class="hljs-literal">None</span>, output_layouts=<span class="hljs-literal">None</span>, use_local_output: <span class="hljs-built_in">bool</span> = <span class="hljs-literal">True</span></span>):
<span class="hljs-variable language_">self</span>.input_layouts = input_layouts <span class="hljs-keyword">or</span> Replicate()
<span class="hljs-variable language_">self</span>.output_layouts = output_layouts <span class="hljs-keyword">if</span> output_layouts <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span> <span class="hljs-keyword">else</span> Shard(-<span class="hljs-number">1</span>)
<span class="hljs-variable language_">self</span>.use_local_output = use_local_output<!----></pre></div><!----></li> <li><p>Implémentez <code>shard_param</code> pour encapsuler un paramètre sous forme de placeholder <code>DTensor</code>. Il s’exécute sur des tenseurs meta, de sorte que <code>distribute_tensor</code> ne construit que les métadonnées et ne déplace aucune donnée. Passez <code>src_data_rank=None</code> car il n’existe pas encore de tenseur complet à disperser.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">def</span> <span class="hljs-title function_">shard_param</span>(<span class="hljs-params">self, module, param, mesh</span>):
meta = module._parameters.get(param)
<span class="hljs-keyword">if</span> meta <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
<span class="hljs-keyword">return</span>
<span class="hljs-comment"># Output features live on dim 0 for a 2D weight and dim -1 for a 1D bias</span>
placement = Shard(<span class="hljs-number">1</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(module, torch.nn.Embedding) <span class="hljs-keyword">else</span> Shard(meta.ndim - <span class="hljs-number">2</span>)
module._parameters[param] = torch.nn.Parameter(
distribute_tensor(meta, mesh, [placement], src_data_rank=<span class="hljs-literal">None</span>),
requires_grad=meta.requires_grad,
)<!----></pre></div><!----></li> <li><p>Implémentez les transformations d’entrée et de sortie. <code>install_forward</code> les appelle autour du forward d’origine du module, de sorte qu’elles n’ont qu’à déplacer les tenseurs entre les différents layouts. Le partitionnement par colonnes s’attend à une entrée répliquée et produit une sortie fragmentée sur la dernière dimension.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">def</span> <span class="hljs-title function_">transform_inputs_pre_forward</span>(<span class="hljs-params">self, module, args, kwargs, mesh</span>):
x = args[<span class="hljs-number">0</span>]
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(x, DTensor):
x = DTensor.from_local(x, mesh, [<span class="hljs-variable language_">self</span>.input_layouts], run_check=<span class="hljs-literal">False</span>)
<span class="hljs-keyword">if</span> x.placements != (Replicate(),):
x = x.redistribute(placements=[Replicate()])
<span class="hljs-keyword">return</span> (x,) + args[<span class="hljs-number">1</span>:], kwargs
<span class="hljs-keyword">def</span> <span class="hljs-title function_">transform_output_post_forward</span>(<span class="hljs-params">self, module, output, mesh</span>):
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(output, DTensor):
output = DTensor.from_local(output, mesh, [Shard(-<span class="hljs-number">1</span>)], run_check=<span class="hljs-literal">False</span>)
<span class="hljs-keyword">if</span> output.placements != (<span class="hljs-variable language_">self</span>.output_layouts,):
output = output.redistribute(placements=[<span class="hljs-variable language_">self</span>.output_layouts])
<span class="hljs-keyword">return</span> output.to_local() <span class="hljs-keyword">if</span> <span class="hljs-variable language_">self</span>.use_local_output <span class="hljs-keyword">else</span> output<!----></pre></div><!----> <p>Le <code>ColwiseParallel</code> fourni ajoute des chemins rapides par-dessus ce mécanisme, qui évitent l’aller-retour <code>DTensor</code> pour l’inférence sur des <code>nn.Linear</code> simples et pour les modules quantisés nécessitant des tenseurs locaux. Lisez le code source avant de le copier si votre stratégie nécessite le même traitement.</p></li> <li><p>Enregistrez la stratégie afin qu'un <code>tp_plan</code> puisse la nommer. L'enregistrement prend une instance de stratégie, de sorte que les placements que vous passez à <code>__init__</code> sont stockés avec le nom. Notez le <code>()</code> ci-dessous.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, DistributedConfig
<span class="hljs-keyword">from</span> transformers.distributed.parallel_utils <span class="hljs-keyword">import</span> ALL_PARALLEL_STYLES
ALL_PARALLEL_STYLES.register(<span class="hljs-string">&quot;colwise_custom&quot;</span>, ColwiseParallel())
tp_plan = {
<span class="hljs-string">&quot;model.layers.*.self_attn.q_proj&quot;</span>: <span class="hljs-string">&quot;colwise_custom&quot;</span>,
...
}
distributed_config = DistributedConfig(tp_size=<span class="hljs-number">4</span>, tp_plan=tp_plan)
model = AutoModelForCausalLM.from_pretrained(
<span class="hljs-string">&quot;meta-llama/Meta-Llama-3-8B-Instruct&quot;</span>,
dtype=torch.bfloat16,
distributed_config=distributed_config,
)<!----></pre></div><!----></li></ol> <!--[1--><h2 class="relative group"><a id="benchmarks" 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="#benchmarks"><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><!---->Benchmarks<!----></span></h2><!--]--><!----> <p>Le parallélisme de tenseurs accélère considérablement l’inférence, en particulier pour les grandes tailles de lot ou les séquences longues.</p> <p>Ce graphique montre l’accélération attendue pour un seul passage avant sur <a href="./model_doc/llama">Llama</a> avec une longueur de séquence de 512.</p> <div style="text-align: center"><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/Meta-Llama-3-8B-Instruct%2C%20seqlen%20%3D%20512%2C%20python%2C%20w_%20compile.png"/></div> <!--[1--><h2 class="relative group"><a id="design-implementation" 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="#design-implementation"><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><!---->Implémentation de la conception<!----></span></h2><!--]--><!----> <p>Transformers implémente le parallélisme de tenseurs de manière indépendante du framework. Il s’appuie sur <a href="https://docs.pytorch.org/tutorials/recipes/distributed_device_mesh.html" rel="nofollow">DeviceMesh</a> et <a href="https://docs.pytorch.org/docs/stable/distributed.tensor.html" rel="nofollow">DTensor</a> de <a href="https://docs.pytorch.org/tutorials/beginner/dist_overview.html" rel="nofollow">torch.distributed</a> pour fournir une interface simple et extensible.</p> <!--[2--><h3 class="relative group"><a id="devicemesh" 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="#devicemesh"><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><!---->DeviceMesh<!----></span></h3><!--]--><!----> <p><code>DeviceMesh</code> crée une grille multi-dimensionnelle d’appareils qui communiquent entre eux. Les différentes stratégies de parallélisation nécessitent des motifs de communication distincts. Créez un <code>DeviceMesh</code> avec plusieurs sous-grilles pour gérer ces motifs.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> torch.distributed.device_mesh <span class="hljs-keyword">import</span> init_device_mesh
<span class="hljs-comment"># Create a 1D mesh of 4 accelerators</span>
device_type = torch.accelerator.current_accelerator().<span class="hljs-built_in">type</span>
device_mesh = init_device_mesh(device_type, (<span class="hljs-number">4</span>,), mesh_dim_names=[<span class="hljs-string">&quot;tp&quot;</span>])<!----></pre></div><!----> <p>La plupart des stratégies de parallélisation de <code>torch.distributed</code> s’appliquent au maillage lui-même ou à ses sous-maillages. Le maillage gère automatiquement les motifs de communication.</p> <!--[2--><h3 class="relative group"><a id="dtensor" 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="#dtensor"><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><!---->DTensor<!----></span></h3><!--]--><!----> <p><code>DTensor</code> (Distributed Tensor) gère la logique distribuée par-dessus les opérations tensorielles habituelles. Les poids du modèle sous parallélisme de tenseurs sont stockés sous forme de <code>DTensor</code>, ce qui permet à une stratégie de décrire la communication comme un changement de disposition plutôt que comme une opération collective explicite.</p> <p>L'attribut <code>placements</code> indique à PyTorch comment un tenseur est réparti sur les appareils d'un <code>DeviceMesh</code>. Il accepte les valeurs suivantes :</p> <ul><li><p><code>Shard(dimension)</code> répartit un <code>DTensor</code> sur une dimension donnée, sur le <code>DeviceMesh</code> sous lequel il a été construit. Le partitionnement par colonnes sharde la dimension des caractéristiques de sortie du poids et la seule dimension du biais.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!---->weight = DTensor.from_local(weight, device_mesh[<span class="hljs-string">&quot;tp&quot;</span>], placements=[Shard(<span class="hljs-number">0</span>)]) <span class="hljs-comment"># Shard the output features</span>
bias = DTensor.from_local(bias, device_mesh[<span class="hljs-string">&quot;tp&quot;</span>], placements=[Shard(-<span class="hljs-number">1</span>)]) <span class="hljs-comment"># Shard the ONLY dimension</span><!----></pre></div><!----> <p>Le partitionnement par lignes sharde la dimension des caractéristiques d’entrée et réplique le biais, car le biais est ajouté une seule fois après la réduction, et non sur chaque rang.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copié</div><!----></button><!----></div> <pre class="language-python "><!---->weight = DTensor.from_local(weight, device_mesh[<span class="hljs-string">&quot;tp&quot;</span>], placements=[Shard(-<span class="hljs-number">1</span>)]) <span class="hljs-comment"># Shard the input features</span>
bias = DTensor.from_local(bias, device_mesh[<span class="hljs-string">&quot;tp&quot;</span>], placements=[Replicate()]) <span class="hljs-comment"># Replicate bias across all GPUs</span><!----></pre></div><!----></li> <li><p><code>Replicate()</code> réplique un <code>DTensor</code> sur le <code>DeviceMesh</code>, créant une copie complète du tenseur sur chaque appareil.</p></li> <li><p><code>Partial()</code> marque un tenseur comme en attente d’une réduction. La sortie avant d’une couche par ligne est <code>Partial()</code>, et sa redistribution vers <code>Replicate()</code> déclenche l’all-reduce.</p></li></ul> <!--[1--><h2 class="relative group"><a id="resources" 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="#resources"><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><!---->Ressources<!----></span></h2><!--]--><!----> <ul><li><p>La section <a href="https://huggingface.co/spaces/nanotron/ultrascale-playbook?section=tensor_parallelism" rel="nofollow">Ultra-Scale Playbook</a> sur le parallélisme de tenseurs fournit plus de détails.</p></li> <li><p>Consultez le guide sur le <a href="./expert_parallelism">expert parallelism</a> si vous utilisez un modèle de type mixture-of-experts (MoE). Ces modèles prennent en charge le tensor parallelism et l'expert parallelism.</p></li> <li><p>Lisez l’article de blog <a href="https://huggingface.co/blog/qgallouedec/tp" rel="nofollow">Tensor Parallelism (TP) in Transformers: 5 Minutes to Understand</a> pour un aperçu rapide du parallélisme de tenseurs et découvrez comment les configurations parallèles par colonne et par ligne diffèrent.</p></li> <li><p>Consultez le guide d’entraînement sur le <a href="./tensor_parallelism">Tensor parallelism</a> pour apprendre à l’utiliser dans un contexte d’entraînement.</p></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/en/perf_infer_gpu_multi.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_gkmhm8 = {
base: "/docs/transformers/main/en",
assets: "/docs/transformers/main/en"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/transformers/main/en/_app/immutable/entry/start.DGrKXpv6.js"),
import("/docs/transformers/main/en/_app/immutable/entry/app.-AoMVxrm.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 5],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
66.9 kB
·
Xet hash:
4c13099f48a857443b2453c76c0d0e63c59c1820e00b2484c723ae600a3bc4d3

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