lynx   »   [go: up one dir, main page]

Transformers documentation

ExecuTorch

You are viewing v4.53.1 version. A newer version v4.56.2 is available.
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

ExecuTorch

ExecuTorch ๋Š” ์›จ์–ด๋Ÿฌ๋ธ”, ์ž„๋ฒ ๋””๋“œ ์žฅ์น˜, ๋งˆ์ดํฌ๋กœ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ํฌํ•จํ•œ ๋ชจ๋ฐ”์ผ ๋ฐ ์—ฃ์ง€ ์žฅ์น˜์—์„œ ์˜จ๋””๋ฐ”์ด์Šค ์ถ”๋ก  ๊ธฐ๋Šฅ์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋Š” ์ข…ํ•ฉ ์†”๋ฃจ์…˜์ž…๋‹ˆ๋‹ค. PyTorch ์ƒํƒœ๊ณ„์— ์†ํ•ด์žˆ์œผ๋ฉฐ, ์ด์‹์„ฑ, ์ƒ์‚ฐ์„ฑ, ์„ฑ๋Šฅ์— ์ค‘์ ์„ ๋‘” PyTorch ๋ชจ๋ธ ๋ฐฐํฌ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

ExecuTorch๋Š” ๋ฐฑ์—”๋“œ ์œ„์ž„, ์‚ฌ์šฉ์ž ์ •์˜ ์ปดํŒŒ์ผ๋Ÿฌ ๋ณ€ํ™˜, ๋ฉ”๋ชจ๋ฆฌ ๊ณ„ํš ๋“ฑ ๋ชจ๋ธ, ์žฅ์น˜ ๋˜๋Š” ํŠน์ • ์œ ์ฆˆ์ผ€์ด์Šค ๋งž์ถค ์ตœ์ ํ™”๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ง„์ž…์ ์„ ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ExecuTorch๋ฅผ ์‚ฌ์šฉํ•ด ์—ฃ์ง€ ์žฅ์น˜์—์„œ PyTorch ๋ชจ๋ธ์„ ์‹คํ–‰ํ•˜๋Š” ์ฒซ ๋ฒˆ์งธ ๋‹จ๊ณ„๋Š” ๋ชจ๋ธ์„ ์ต์ŠคํฌํŠธํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด ์ž‘์—…์€ PyTorch API์ธ torch.export๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

ExecuTorch ํ†ตํ•ฉ

torch.export๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๐Ÿค— Transformers๋ฅผ ์ต์ŠคํฌํŠธ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ†ตํ•ฉ ์ง€์ ์ด ๊ฐœ๋ฐœ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ํ†ตํ•ฉ์˜ ๋ชฉํ‘œ๋Š” ์ต์ŠคํฌํŠธ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ์ต์ŠคํฌํŠธํ•œ ์•„ํ‹ฐํŒฉํŠธ๊ฐ€ ExecuTorch์—์„œ ํšจ์œจ์ ์œผ๋กœ ์‹คํ–‰๋  ์ˆ˜ ์žˆ๋„๋ก ๋” ์ถ•์†Œํ•˜๊ณ  ์ตœ์ ํ™”ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํŠนํžˆ ๋ชจ๋ฐ”์ผ ๋ฐ ์—ฃ์ง€ ์œ ์ฆˆ์ผ€์ด์Šค์— ์ค‘์ ์„ ๋‘๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

class transformers.TorchExportableModuleWithStaticCache

< >

( model: PreTrainedModel )

A recipe module designed to make a PreTrainedModel exportable with torch.export, specifically for decoder-only LM to StaticCache. This module ensures that the exported model is compatible with further lowering and execution in ExecuTorch.

Note: This class is specifically designed to support export process using torch.export in a way that ensures the model can be further lowered and run efficiently in ExecuTorch.

forward

< >

( input_ids: Tensor cache_position: Tensor ) โ†’ torch.Tensor

Parameters

  • input_ids (torch.Tensor) — Tensor representing current input token id to the module.
  • cache_position (torch.Tensor) — Tensor representing current input position in the cache.

Returns

torch.Tensor

Logits output from the model.

Forward pass of the module, which is compatible with the ExecuTorch runtime.

This forward adapter serves two primary purposes:

  1. Making the Model torch.export-Compatible: The adapter hides unsupported objects, such as the Cache, from the graph inputs and outputs, enabling the model to be exportable using torch.export without encountering issues.

  2. Ensuring Compatibility with ExecuTorch runtime: The adapter matches the modelโ€™s forward signature with that in executorch/extension/llm/runner, ensuring that the exported model can be executed in ExecuTorch out-of-the-box.

transformers.convert_and_export_with_cache

< >

( model: PreTrainedModel example_input_ids: typing.Optional[torch.Tensor] = None example_cache_position: typing.Optional[torch.Tensor] = None dynamic_shapes: typing.Optional[dict] = None strict: typing.Optional[bool] = None ) โ†’ Exported program (torch.export.ExportedProgram)

Parameters

  • model (PreTrainedModel) — The pretrained model to be exported.
  • example_input_ids (Optional[torch.Tensor]) — Example input token id used by torch.export.
  • example_cache_position (Optional[torch.Tensor]) — Example current cache position used by torch.export.
  • dynamic_shapes(Optional[dict]) — Dynamic shapes used by torch.export.
  • strict(Optional[bool]) — Flag to instruct torch.export to use torchdynamo.

Returns

Exported program (torch.export.ExportedProgram)

The exported program generated via torch.export.

Convert a PreTrainedModel into an exportable module and export it using torch.export, ensuring the exported model is compatible with ExecuTorch.

< > Update on GitHub

ะ›ัƒั‡ัˆะธะน ั‡ะฐัั‚ะฝั‹ะน ั…ะพัั‚ะธะฝะณ