如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
本镜像为官方ExecuTorch Docker镜像,基于openEuler系统构建,由openEuler CloudNative SIG维护。ExecuTorch是PyTorch的统一设备端AI模型部署解决方案,支持从智能手机到微控制器等多种设备,致力于提供隐私保护、高性能和高可移植性的模型部署能力。该镜像可直接用于AI模型的导出、优化和部署,无需手动C++重写或格式转换,适用于研究到生产环境的无缝过渡。
每个ExecuTorch Docker镜像的标签由ExecuTorch版本、基础镜像版本组成,具体信息如下:
| 标签 | 当前版本 | 架构 |
|---|---|---|
| 1.0.0-torch2.9.0-python3.11-oe2403sp2 | 基于openEuler 24.03-LTS-SP2的ExecuTorch 1.0.0 | aarch64 |
支持的设备
使用容器设置环境
bash# 启动ExecuTorch容器 docker run --rm --name executorch -it --entrypoint bash openeuler/executorch:latest
pythonimport torch from executorch.exir import to_edge_transform_and_lower from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner # 1. 导出PyTorch模型 model = MyModel().eval() example_inputs = (torch.randn(1, 3, 224, 224),) exported_program = torch.export.export(model, example_inputs) # 2. 针对目标硬件优化(通过单行代码切换后端) program = to_edge_transform_and_lower( exported_program, partitioner=[XnnpackPartitioner()] # CPU | CoreMLPartitioner()(iOS)| QnnPartitioner()(Qualcomm) ).to_executorch() # 3. 保存部署文件 with open("model.pte", "wb") as f: f.write(program.buffer) # (可选)通过ExecuTorch运行时的pybind API本地测试 from executorch.runtime import Runtime runtime = Runtime.get() method = runtime.load_program("model.pte").load_method("forward") outputs = method.execute([torch.randn(1, 3, 224, 224)])
C++
cpp#include <executorch/extension/module/module.h> #include <executorch/extension/tensor/tensor.h> Module module("model.pte"); auto tensor = make_tensor_ptr({2, 2}, {1.0f, 2.0f, 3.0f, 4.0f}); auto outputs = module.forward(tensor);
Swift(iOS)
swiftimport ExecuTorch let module = Module(filePath: "model.pte") let input = Tensor<Float>([1.0, 2.0, 3.0, 4.0], shape: [2, 2]) let outputs = try module.forward(input)
Kotlin(Android)
kotlinval module = Module.load("model.pte") val inputTensor = Tensor.fromBlob(floatArrayOf(1.0f, 2.0f, 3.0f, 4.0f), longArrayOf(2, 2)) val outputs = module.forward(EValue.from(inputTensor))
使用export_llm脚本或https://github.com/huggingface/optimum-executorch%E5%AF%BC%E5%87%BALlama%E6%A8%A1%E5%9E%8B%EF%BC%9A
bash# 使用export_llm python -m executorch.extension.llm.export.export_llm --model llama3_2 --output llama.pte # 使用Optimum-ExecuTorch optimum-cli export executorch \ --model meta-llama/Llama-3.2-1B \ --task text-generation \ --recipe xnnpack \ --output_dir llama_model
通过LLM运行器API在设备端运行:
C++
cpp#include <executorch/extension/llm/runner/text_llm_runner.h> auto runner = create_llama_runner("llama.pte", "tiktoken.bin"); executorch::extension::llm::GenerationConfig config{ .seq_len = 128, .temperature = 0.8f}; runner->generate("Hello, how are you?", config);
Swift(iOS)
swiftimport ExecuTorchLLM let runner = TextRunner(modelPath: "llama.pte", tokenizerPath: "tiktoken.bin") try runner.generate("Hello, how are you?", Config { $0.sequenceLength = 128 }) { token in print(token, terminator: "") }
Kotlin(Android)
API文档 • https://github.com/meta-pytorch/executorch-examples/tree/main/llm/android/LlamaDemo
kotlinval llmModule = LlmModule("llama.pte", "tiktoken.bin", 0.8f) llmModule.load() llmModule.generate("Hello, how are you?", 128, object : LlmCallback { override fun onResult(result: String) { print(result) } override fun onStats(stats: String) { } })
对于多模态模型(视觉、音频),可使用MultiModal运行器API,该API扩展了LLM运行器以处理文本之外的图像和音频输入。详见Llava和Voxtral示例。
完整工作流(包括量化、移动部署和高级选项)请参见examples/models/llama。
如有任何问题或需要使用特定功能,请在openeuler-docker-images提交issue或pull request。
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务