Buckets:

download
raw
21.4 kB
import"../chunks/DsnmJJEf.js";import{i as x,h as G,C as D,H as t,a as l,D as i,E,s as C}from"../chunks/BtE7mKSK.js";import{p as R,o as W,s as e,f as v,a as r,b as I,c as d,d as p,r as c,n as V}from"../chunks/jDjavuwI.js";import{E as P}from"../chunks/SrSJA0zO.js";const Q='{"title":"LLaDA2","local":"llada2","sections":[{"title":"Usage","local":"usage","sections":[],"depth":2},{"title":"Callbacks","local":"callbacks","sections":[],"depth":2},{"title":"Recommended parameters","local":"recommended-parameters","sections":[],"depth":2},{"title":"LLaDA2Pipeline","local":"diffusers.LLaDA2Pipeline","sections":[],"depth":2},{"title":"LLaDA2PipelineOutput","local":"diffusers.LLaDA2PipelineOutput","sections":[],"depth":2}],"depth":1}';var X=p('<meta name="hf:doc:metadata"/>'),q=p("<p>Examples:</p> <!>",1),S=p(`<p></p> <!> <!> <p><a href="https://huggingface.co/collections/inclusionAI/llada21" rel="nofollow">LLaDA2</a> is a family of discrete diffusion language models
that generate text through block-wise iterative refinement. Instead of autoregressive token-by-token generation,
LLaDA2 starts with a fully masked sequence and progressively unmasks tokens by confidence over multiple refinement
steps.</p> <!> <!> <!> <p>Callbacks run after each refinement step. Pass <code>callback_on_step_end_tensor_inputs</code> to select which tensors are
included in <code>callback_kwargs</code>. In the current implementation, <code>block_x</code> (the sequence window being refined) and <code>transfer_index</code> (mask-filling commit mask) are provided; return <code>&#123;"block_x": ...&#125;</code> from the callback to replace the
window.</p> <!> <!> <p>LLaDA2.1 models support two modes:</p> <table><thead><tr><th>Mode</th><th><code>threshold</code></th><th><code>editing_threshold</code></th><th><code>max_post_steps</code></th></tr></thead><tbody><tr><td>Quality</td><td>0.7</td><td>0.5</td><td>16</td></tr><tr><td>Speed</td><td>0.5</td><td><code>None</code></td><td>16</td></tr></tbody></table> <p>Pass <code>editing_threshold=None</code>, <code>0.0</code>, or a negative value to turn off post-mask editing.</p> <p>For LLaDA2.0 models, disable editing by passing <code>editing_threshold=None</code> or <code>0.0</code>.</p> <p>For all models: <code>block_length=32</code>, <code>temperature=0.0</code>, <code>num_inference_steps=32</code>.</p> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Pipeline for LLaDA2-style discrete diffusion text generation via block-wise iterative refinement.</p> <p>This pipeline maintains a template sequence filled with a <code>mask_token_id</code> and refines it in blocks. In each
refinement step, it samples candidate tokens for the active block and commits a subset based on confidence.</p> <p>The model is expected to accept an attention mask and <code>position_ids</code>, and to return logits of shape <code>[batch, seq, vocab_size]</code>.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Generate text with block-wise refinement.</p> <!></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!></div> <!> <p></p>`,1);function O(w,U){R(U,!1),W(()=>{new URLSearchParams(window.location.search).get("fw")}),x();var m=S();G("dfmmjk",o=>{var a=X();C(a,"content",Q),r(o,a)});var _=e(v(m),2);D(_,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var u=e(_,2);t(u,{title:"LLaDA2",local:"llada2",headingTag:"h1"});var h=e(u,4);t(h,{title:"Usage",local:"usage",headingTag:"h2"});var f=e(h,2);l(f,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0lMkMlMjBBdXRvVG9rZW5pemVyJTBBJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEJsb2NrUmVmaW5lbWVudFNjaGVkdWxlciUyQyUyMExMYURBMlBpcGVsaW5lJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJpbmNsdXNpb25BSSUyRkxMYURBMi4xLW1pbmklMjIlMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9pZCUyQyUyMHRydXN0X3JlbW90ZV9jb2RlJTNEVHJ1ZSUyQyUyMGR0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMjBkZXZpY2VfbWFwJTNEJTIyYXV0byUyMiUwQSklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHRydXN0X3JlbW90ZV9jb2RlJTNEVHJ1ZSklMEFzY2hlZHVsZXIlMjAlM0QlMjBCbG9ja1JlZmluZW1lbnRTY2hlZHVsZXIoKSUwQSUwQXBpcGUlMjAlM0QlMjBMTGFEQTJQaXBlbGluZShtb2RlbCUzRG1vZGVsJTJDJTIwc2NoZWR1bGVyJTNEc2NoZWR1bGVyJTJDJTIwdG9rZW5pemVyJTNEdG9rZW5pemVyKSUwQW91dHB1dCUyMCUzRCUyMHBpcGUoJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTNEJTIyV3JpdGUlMjBhJTIwc2hvcnQlMjBwb2VtJTIwYWJvdXQlMjB0aGUlMjBvY2Vhbi4lMjIlMkMlMEElMjAlMjAlMjAlMjBnZW5fbGVuZ3RoJTNEMjU2JTJDJTBBJTIwJTIwJTIwJTIwYmxvY2tfbGVuZ3RoJTNEMzIlMkMlMEElMjAlMjAlMjAlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMzIlMkMlMEElMjAlMjAlMjAlMjB0aHJlc2hvbGQlM0QwLjclMkMlMEElMjAlMjAlMjAlMjBlZGl0aW5nX3RocmVzaG9sZCUzRDAuNSUyQyUwQSUyMCUyMCUyMCUyMG1heF9wb3N0X3N0ZXBzJTNEMTYlMkMlMEElMjAlMjAlMjAlMjB0ZW1wZXJhdHVyZSUzRDAuMCUyQyUwQSklMEFwcmludChvdXRwdXQudGV4dHMlNUIwJTVEKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> BlockRefinementScheduler, LLaDA2Pipeline
model_id = <span class="hljs-string">&quot;inclusionAI/LLaDA2.1-mini&quot;</span>
model = AutoModelForCausalLM.from_pretrained(
model_id, trust_remote_code=<span class="hljs-literal">True</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">&quot;auto&quot;</span>
)
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=<span class="hljs-literal">True</span>)
scheduler = BlockRefinementScheduler()
pipe = LLaDA2Pipeline(model=model, scheduler=scheduler, tokenizer=tokenizer)
output = pipe(
prompt=<span class="hljs-string">&quot;Write a short poem about the ocean.&quot;</span>,
gen_length=<span class="hljs-number">256</span>,
block_length=<span class="hljs-number">32</span>,
num_inference_steps=<span class="hljs-number">32</span>,
threshold=<span class="hljs-number">0.7</span>,
editing_threshold=<span class="hljs-number">0.5</span>,
max_post_steps=<span class="hljs-number">16</span>,
temperature=<span class="hljs-number">0.0</span>,
)
<span class="hljs-built_in">print</span>(output.texts[<span class="hljs-number">0</span>])`,lang:"py",wrap:!1});var g=e(f,2);t(g,{title:"Callbacks",local:"callbacks",headingTag:"h2"});var b=e(g,4);l(b,{code:"ZGVmJTIwb25fc3RlcF9lbmQocGlwZSUyQyUyMHN0ZXAlMkMlMjB0aW1lc3RlcCUyQyUyMGNhbGxiYWNrX2t3YXJncyklM0ElMEElMjAlMjAlMjAlMjBibG9ja194JTIwJTNEJTIwY2FsbGJhY2tfa3dhcmdzJTVCJTIyYmxvY2tfeCUyMiU1RCUwQSUyMCUyMCUyMCUyMCUyMyUyMEluc3BlY3QlMjBvciUyMG1vZGlmeSUyMCU2MGJsb2NrX3glNjAlMjBoZXJlLiUwQSUyMCUyMCUyMCUyMHJldHVybiUyMCU3QiUyMmJsb2NrX3glMjIlM0ElMjBibG9ja194JTdEJTBBJTBBb3V0JTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlM0QlMjJXcml0ZSUyMGElMjBzaG9ydCUyMHBvZW0uJTIyJTJDJTBBJTIwJTIwJTIwJTIwY2FsbGJhY2tfb25fc3RlcF9lbmQlM0Rvbl9zdGVwX2VuZCUyQyUwQSUyMCUyMCUyMCUyMGNhbGxiYWNrX29uX3N0ZXBfZW5kX3RlbnNvcl9pbnB1dHMlM0QlNUIlMjJibG9ja194JTIyJTVEJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">on_step_end</span>(<span class="hljs-params">pipe, step, timestep, callback_kwargs</span>):
block_x = callback_kwargs[<span class="hljs-string">&quot;block_x&quot;</span>]
<span class="hljs-comment"># Inspect or modify \`block_x\` here.</span>
<span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;block_x&quot;</span>: block_x}
out = pipe(
prompt=<span class="hljs-string">&quot;Write a short poem.&quot;</span>,
callback_on_step_end=on_step_end,
callback_on_step_end_tensor_inputs=[<span class="hljs-string">&quot;block_x&quot;</span>],
)`,lang:"py",wrap:!1});var M=e(b,2);t(M,{title:"Recommended parameters",local:"recommended-parameters",headingTag:"h2"});var y=e(M,12);t(y,{title:"LLaDA2Pipeline",local:"diffusers.LLaDA2Pipeline",headingTag:"h2"});var n=e(y,2),k=d(n);i(k,{name:"class diffusers.LLaDA2Pipeline",anchor:"diffusers.LLaDA2Pipeline",source:"https://github.com/huggingface/diffusers/blob/vr_14192/src/diffusers/pipelines/llada2/pipeline_llada2.py#L59",parameters:[{name:"model",val:": Any"},{name:"scheduler",val:": BlockRefinementScheduler"},{name:"tokenizer",val:": Any | None = None"}]});var J=e(k,8),L=d(J);i(L,{name:"__call__",anchor:"diffusers.LLaDA2Pipeline.__call__",source:"https://github.com/huggingface/diffusers/blob/vr_14192/src/diffusers/pipelines/llada2/pipeline_llada2.py#L242",parameters:[{name:"prompt",val:": str | list[str] | None = None"},{name:"messages",val:": list[dict[str, str]] | None = None"},{name:"input_ids",val:": torch.LongTensor | None = None"},{name:"attention_mask",val:": torch.LongTensor | None = None"},{name:"use_chat_template",val:": bool = True"},{name:"add_generation_prompt",val:": bool = True"},{name:"gen_length",val:": int = 2048"},{name:"block_length",val:": int | None = None"},{name:"num_inference_steps",val:": int = 32"},{name:"temperature",val:": float = 0.0"},{name:"top_p",val:": float | None = None"},{name:"top_k",val:": int | None = None"},{name:"sampling_method",val:": str = 'multinomial'"},{name:"threshold",val:": float = 0.7"},{name:"editing_threshold",val:": float | None = 0.5"},{name:"max_post_steps",val:": int = 16"},{name:"minimal_topk",val:": int = 1"},{name:"eos_early_stop",val:": bool = True"},{name:"eos_token_id",val:": int | None = None"},{name:"mask_token_id",val:": int | None = None"},{name:"generator",val:": torch.Generator | None = None"},{name:"output_type",val:": str = 'text'"},{name:"return_dict",val:": bool = True"},{name:"callback_on_step_end",val:": Callable[[int, int, dict], None] | PipelineCallback | MultiPipelineCallbacks | None = None"},{name:"callback_on_step_end_tensor_inputs",val:": list[str] | None = None"}],parametersDescription:[{anchor:"diffusers.LLaDA2Pipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
Prompt text. When <code>use_chat_template</code> is <code>True</code> (default) and a tokenizer with a chat template is
available, the prompt is wrapped in a chat message before tokenization.`,name:"prompt"},{anchor:"diffusers.LLaDA2Pipeline.__call__.messages",description:`<strong>messages</strong> (<code>List[Dict[str, str]]</code>, <em>optional</em>) &#x2014;
Chat messages to encode (e.g. <code>[{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Hello&quot;}]</code>). Takes precedence over <code>prompt</code>
when provided. Requires a tokenizer with <code>apply_chat_template</code>.`,name:"messages"},{anchor:"diffusers.LLaDA2Pipeline.__call__.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code>, <em>optional</em>) &#x2014;
Pre-tokenized input IDs. Takes precedence over <code>prompt</code> and <code>messages</code>.`,name:"input_ids"},{anchor:"diffusers.LLaDA2Pipeline.__call__.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.LongTensor</code>, <em>optional</em>) &#x2014;
Per-token mask (1 for valid prompt tokens, 0 for padding) matching the shape of <code>input_ids</code>. Only used
when <code>input_ids</code> is provided. When omitted (and <code>input_ids</code> is given), all positions are treated as
valid. When constructing inputs from <code>prompt</code> / <code>messages</code>, the tokenizer&#x2019;s mask is carried through
automatically.`,name:"attention_mask"},{anchor:"diffusers.LLaDA2Pipeline.__call__.use_chat_template",description:`<strong>use_chat_template</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
Whether to wrap the prompt in a chat template.`,name:"use_chat_template"},{anchor:"diffusers.LLaDA2Pipeline.__call__.add_generation_prompt",description:`<strong>add_generation_prompt</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
Whether to add the generation prompt when using chat templates.`,name:"add_generation_prompt"},{anchor:"diffusers.LLaDA2Pipeline.__call__.gen_length",description:`<strong>gen_length</strong> (<code>int</code>) &#x2014;
Number of tokens to generate.`,name:"gen_length"},{anchor:"diffusers.LLaDA2Pipeline.__call__.block_length",description:`<strong>block_length</strong> (<code>int</code>, <em>optional</em>) &#x2014;
Block size for refinement. If not provided, the scheduler&#x2019;s configured <code>block_length</code> is used.`,name:"block_length"},{anchor:"diffusers.LLaDA2Pipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>) &#x2014;
Number of refinement steps per block.`,name:"num_inference_steps"},{anchor:"diffusers.LLaDA2Pipeline.__call__.temperature",description:`<strong>temperature</strong> (<code>float</code>) &#x2014;
Sampling temperature.`,name:"temperature"},{anchor:"diffusers.LLaDA2Pipeline.__call__.top_p",description:`<strong>top_p</strong> (<code>float</code>, <em>optional</em>) &#x2014;
Nucleus sampling cutoff.`,name:"top_p"},{anchor:"diffusers.LLaDA2Pipeline.__call__.top_k",description:`<strong>top_k</strong> (<code>int</code>, <em>optional</em>) &#x2014;
Top-k sampling cutoff.`,name:"top_k"},{anchor:"diffusers.LLaDA2Pipeline.__call__.sampling_method",description:`<strong>sampling_method</strong> (<code>str</code>) &#x2014;
Sampling method (<code>auto</code>, <code>greedy</code>, <code>multinomial</code>).`,name:"sampling_method"},{anchor:"diffusers.LLaDA2Pipeline.__call__.threshold",description:`<strong>threshold</strong> (<code>float</code>) &#x2014;
Confidence threshold for committing tokens.`,name:"threshold"},{anchor:"diffusers.LLaDA2Pipeline.__call__.editing_threshold",description:`<strong>editing_threshold</strong> (<code>float</code>, <em>optional</em>) &#x2014;
Confidence threshold for editing already-committed (non-mask) tokens. When positive, after all mask
tokens in a block are resolved, the pipeline continues refining: if the model predicts a different
token with confidence above this threshold, the existing token is replaced. Set to <code>None</code>, <code>0.0</code>, or a
negative value to disable editing. Defaults to <code>0.5</code>.`,name:"editing_threshold"},{anchor:"diffusers.LLaDA2Pipeline.__call__.max_post_steps",description:`<strong>max_post_steps</strong> (<code>int</code>) &#x2014;
Maximum number of additional refinement iterations after all mask tokens in a block are resolved. Only
used when <code>editing_threshold</code> is enabled. Defaults to <code>16</code>.`,name:"max_post_steps"},{anchor:"diffusers.LLaDA2Pipeline.__call__.minimal_topk",description:`<strong>minimal_topk</strong> (<code>int</code>) &#x2014;
Minimum number of tokens to commit per step.`,name:"minimal_topk"},{anchor:"diffusers.LLaDA2Pipeline.__call__.eos_early_stop",description:`<strong>eos_early_stop</strong> (<code>bool</code>) &#x2014;
Whether to stop after committing EOS in a block.`,name:"eos_early_stop"},{anchor:"diffusers.LLaDA2Pipeline.__call__.eos_token_id",description:`<strong>eos_token_id</strong> (<code>int</code>, <em>optional</em>) &#x2014;
EOS token ID to use for early stopping.`,name:"eos_token_id"},{anchor:"diffusers.LLaDA2Pipeline.__call__.mask_token_id",description:`<strong>mask_token_id</strong> (<code>int</code>, <em>optional</em>) &#x2014;
Mask token ID to use for the template.`,name:"mask_token_id"},{anchor:"diffusers.LLaDA2Pipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code>, <em>optional</em>) &#x2014;
RNG for sampling.`,name:"generator"},{anchor:"diffusers.LLaDA2Pipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, defaults to <code>&quot;text&quot;</code>) &#x2014;
Output format. <code>&quot;text&quot;</code> decodes sequences into strings (requires a tokenizer). <code>&quot;seq&quot;</code> returns raw
token ID sequences only.`,name:"output_type"},{anchor:"diffusers.LLaDA2Pipeline.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to return a <a href="/docs/diffusers/pr_14192/en/api/pipelines/llada2#diffusers.LLaDA2PipelineOutput">LLaDA2PipelineOutput</a> instead of a tuple.`,name:"return_dict"},{anchor:"diffusers.LLaDA2Pipeline.__call__.callback_on_step_end",description:`<strong>callback_on_step_end</strong> (<code>Callable</code> or <code>PipelineCallback</code>, <em>optional</em>) &#x2014;
Callback executed after each refinement step with signature <code>callback_on_step_end(self, step: int, timestep: int, callback_kwargs: Dict)</code>.`,name:"callback_on_step_end"},{anchor:"diffusers.LLaDA2Pipeline.__call__.callback_on_step_end_tensor_inputs",description:`<strong>callback_on_step_end_tensor_inputs</strong> (<code>List[str]</code>, <em>optional</em>) &#x2014;
Tensor keys to pass to the callback. Allowed keys: <code>block_x</code>, <code>transfer_index</code>,
<code>editing_transfer_index</code>, <code>sampled_tokens</code>, <code>sampled_probs</code>, <code>active_block</code>.`,name:"callback_on_step_end_tensor_inputs"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>
<p>If <code>return_dict</code> is <code>True</code>, <a
href="/docs/diffusers/pr_14192/en/api/pipelines/llada2#diffusers.LLaDA2PipelineOutput"
>LLaDA2PipelineOutput</a> is returned,
otherwise a <code>tuple</code> is returned where the first element is the generated token IDs (<code>torch.LongTensor</code>)
and the second element is the decoded texts (<code>list[str]</code>), or <code>None</code> when <code>output_type</code> is <code>"seq"</code>.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>
<p><a
href="/docs/diffusers/pr_14192/en/api/pipelines/llada2#diffusers.LLaDA2PipelineOutput"
>LLaDA2PipelineOutput</a> or <code>tuple</code></p>
`});var A=e(L,4);P(A,{anchor:"diffusers.LLaDA2Pipeline.__call__.example",children:(o,a)=>{var T=q(),B=e(v(T),2);l(B,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0lMkMlMjBBdXRvVG9rZW5pemVyJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEJsb2NrUmVmaW5lbWVudFNjaGVkdWxlciUyQyUyMExMYURBMlBpcGVsaW5lJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJpbmNsdXNpb25BSSUyRkxMYURBMi4xLW1pbmklMjIlMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9pZCUyQyUyMHRydXN0X3JlbW90ZV9jb2RlJTNEVHJ1ZSUyQyUyMGR0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMjBkZXZpY2VfbWFwJTNEJTIyYXV0byUyMiUwQSklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHRydXN0X3JlbW90ZV9jb2RlJTNEVHJ1ZSklMEFzY2hlZHVsZXIlMjAlM0QlMjBCbG9ja1JlZmluZW1lbnRTY2hlZHVsZXIoKSUwQSUwQXBpcGUlMjAlM0QlMjBMTGFEQTJQaXBlbGluZShtb2RlbCUzRG1vZGVsJTJDJTIwc2NoZWR1bGVyJTNEc2NoZWR1bGVyJTJDJTIwdG9rZW5pemVyJTNEdG9rZW5pemVyKSUwQW91dHB1dCUyMCUzRCUyMHBpcGUocHJvbXB0JTNEJTIyV2hhdCUyMGlzJTIwdGhlJTIwbWVhbmluZyUyMG9mJTIwbGlmZSUzRiUyMiUyQyUyMGdlbl9sZW5ndGglM0QyNTYpJTBBcHJpbnQob3V0cHV0LnRleHRzJTVCMCU1RCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> BlockRefinementScheduler, LLaDA2Pipeline
<span class="hljs-meta">&gt;&gt;&gt; </span>model_id = <span class="hljs-string">&quot;inclusionAI/LLaDA2.1-mini&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(
<span class="hljs-meta">... </span> model_id, trust_remote_code=<span class="hljs-literal">True</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">&quot;auto&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>scheduler = BlockRefinementScheduler()
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = LLaDA2Pipeline(model=model, scheduler=scheduler, tokenizer=tokenizer)
<span class="hljs-meta">&gt;&gt;&gt; </span>output = pipe(prompt=<span class="hljs-string">&quot;What is the meaning of life?&quot;</span>, gen_length=<span class="hljs-number">256</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(output.texts[<span class="hljs-number">0</span>])`,lang:"python",wrap:!1}),r(o,T)},$$slots:{default:!0}}),c(J),c(n);var j=e(n,2);t(j,{title:"LLaDA2PipelineOutput",local:"diffusers.LLaDA2PipelineOutput",headingTag:"h2"});var s=e(j,2),N=d(s);i(N,{name:"class diffusers.LLaDA2PipelineOutput",anchor:"diffusers.LLaDA2PipelineOutput",source:"https://github.com/huggingface/diffusers/blob/vr_14192/src/diffusers/pipelines/llada2/pipeline_llada2.py#L54",parameters:[{name:"sequences",val:": torch.LongTensor"},{name:"texts",val:": list[str] | None = None"}]}),c(s);var Z=e(s,2);E(Z,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/llada2.md"}),V(2),r(w,m),I()}export{O as component};

Xet Storage Details

Size:
21.4 kB
·
Xet hash:
27ca86ec622551ebf9d8bfff1ccf9a794c8268fe4bc77a2a31974454e90a3466

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