Transformers documentation
ExecuTorch
ExecuTorch
ExecuTorch
๋ ์จ์ด๋ฌ๋ธ, ์๋ฒ ๋๋ ์ฅ์น, ๋ง์ดํฌ๋ก์ปจํธ๋กค๋ฌ๋ฅผ ํฌํจํ ๋ชจ๋ฐ์ผ ๋ฐ ์ฃ์ง ์ฅ์น์์ ์จ๋๋ฐ์ด์ค ์ถ๋ก ๊ธฐ๋ฅ์ ๊ฐ๋ฅํ๊ฒ ํ๋ ์ข
ํฉ ์๋ฃจ์
์
๋๋ค. PyTorch ์ํ๊ณ์ ์ํด์์ผ๋ฉฐ, ์ด์์ฑ, ์์ฐ์ฑ, ์ฑ๋ฅ์ ์ค์ ์ ๋ PyTorch ๋ชจ๋ธ ๋ฐฐํฌ๋ฅผ ์ง์ํฉ๋๋ค.
ExecuTorch๋ ๋ฐฑ์๋ ์์, ์ฌ์ฉ์ ์ ์ ์ปดํ์ผ๋ฌ ๋ณํ, ๋ฉ๋ชจ๋ฆฌ ๊ณํ ๋ฑ ๋ชจ๋ธ, ์ฅ์น ๋๋ ํน์ ์ ์ฆ์ผ์ด์ค ๋ง์ถค ์ต์ ํ๋ฅผ ์ํํ ์ ์๋ ์ง์
์ ์ ๋ช
ํํ๊ฒ ์ ์ํฉ๋๋ค. ExecuTorch๋ฅผ ์ฌ์ฉํด ์ฃ์ง ์ฅ์น์์ PyTorch ๋ชจ๋ธ์ ์คํํ๋ ์ฒซ ๋ฒ์งธ ๋จ๊ณ๋ ๋ชจ๋ธ์ ์ต์คํฌํธํ๋ ๊ฒ์
๋๋ค. ์ด ์์
์ PyTorch API์ธ torch.export
๋ฅผ ์ฌ์ฉํ์ฌ ์ํํฉ๋๋ค.
ExecuTorch ํตํฉ
torch.export
๋ฅผ ์ฌ์ฉํ์ฌ ๐ค Transformers๋ฅผ ์ต์คํฌํธ ํ ์ ์๋๋ก ํตํฉ ์ง์ ์ด ๊ฐ๋ฐ๋๊ณ ์์ต๋๋ค. ์ด ํตํฉ์ ๋ชฉํ๋ ์ต์คํฌํธ๋ฟ๋ง ์๋๋ผ, ์ต์คํฌํธํ ์ํฐํฉํธ๊ฐ ExecuTorch
์์ ํจ์จ์ ์ผ๋ก ์คํ๋ ์ ์๋๋ก ๋ ์ถ์ํ๊ณ ์ต์ ํํ๋ ๊ฒ์
๋๋ค. ํนํ ๋ชจ๋ฐ์ผ ๋ฐ ์ฃ์ง ์ ์ฆ์ผ์ด์ค์ ์ค์ ์ ๋๊ณ ์์ต๋๋ค.
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
< source >( input_ids: Tensor cache_position: Tensor ) โ torch.Tensor
Forward pass of the module, which is compatible with the ExecuTorch runtime.
This forward adapter serves two primary purposes:
Making the Model
torch.export
-Compatible: The adapter hides unsupported objects, such as theCache
, from the graph inputs and outputs, enabling the model to be exportable usingtorch.export
without encountering issues.Ensuring Compatibility with
ExecuTorch
runtime: The adapter matches the modelโs forward signature with that inexecutorch/extension/llm/runner
, ensuring that the exported model can be executed inExecuTorch
out-of-the-box.
transformers.convert_and_export_with_cache
< source >( 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 bytorch.export
. - example_cache_position (
Optional[torch.Tensor]
) — Example current cache position used bytorch.export
. - dynamic_shapes(
Optional[dict]
) — Dynamic shapes used bytorch.export
. - strict(
Optional[bool]
) — Flag to instructtorch.export
to usetorchdynamo
.
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
.