From 1fded918ac4723ac9966363f51ed4500866c5d1d Mon Sep 17 00:00:00 2001 From: xvxuopop Date: Sat, 10 Oct 2026 15:29:22 +0800 Subject: [PATCH] [docs] add security notes to NPU Docker overviews (#10883) --- docker/docker-npu/OVERVIEW.md | 9 +++++++++ docker/docker-npu/OVERVIEW.zh.md | 10 ++++++++++ src/llamafactory/model/patcher.py | 7 ++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docker/docker-npu/OVERVIEW.md b/docker/docker-npu/OVERVIEW.md index 68dba7421..ff1b7dedc 100644 --- a/docker/docker-npu/OVERVIEW.md +++ b/docker/docker-npu/OVERVIEW.md @@ -184,6 +184,15 @@ To build an image with Docker Compose without starting a container, use `docker - Legacy NPU tags are replaced by the `latest-<910b|a3|950>-` format. - Validate the exact driver, firmware, CANN, and SoC combination before production deployment. +## Security Risks +When running containers with these images, be aware of the following security risks: + +- Running as the `root` user: Containers run as the `root` user by default, which can introduce security risks. In production environments, it is recommended to create a non-privileged user to run the application. + +- Lack of CPU and memory resource limits: Not setting resource limits may cause a container to consume excessive system resources and affect host performance. It is recommended to use the `--cpus` and `--memory` parameters to limit resource usage. + +- Device use with `rwm` permissions: The NPU device is assigned read, write, and `mknod` permissions. Although these are required for functionality, the scope of permissions should be carefully evaluated in security-sensitive environments. + ## License and Disclaimer LlamaFactory is distributed under the [Apache License 2.0](../../LICENSE). diff --git a/docker/docker-npu/OVERVIEW.zh.md b/docker/docker-npu/OVERVIEW.zh.md index f4d47fb79..1da1ce636 100644 --- a/docker/docker-npu/OVERVIEW.zh.md +++ b/docker/docker-npu/OVERVIEW.zh.md @@ -184,6 +184,16 @@ docker compose --profile 950-openeuler up -d - 旧式 NPU tag 已由 `latest-<910b|a3|950>-` 格式取代。 - 正式部署前,请验证具体驱动、固件、CANN 和 SoC 组合的兼容性。 +## 安全风险 + +在运行容器时,需要注意以下安全风险: + +- 使用 `root` 用户运行:容器默认以 `root` 用户身份运行,可能带来安全隐患。建议在生产环境中创建非特权用户来运行应用程序。 + +- 缺少 CPU 和内存资源限制:未设置资源限制可能导致容器消耗过多系统资源,影响宿主机性能。建议使用 `--cpus` 和 `--memory` 参数限制资源使用。 + +- 设备使用 `rwm` 权限:为 NPU 设备分配了读写和 `mknod` 权限,虽然功能运行需要,但在安全敏感环境中应谨慎评估权限范围。 + ## 许可证与免责声明 LlamaFactory 基于 [Apache License 2.0](../../LICENSE) 发布。 diff --git a/src/llamafactory/model/patcher.py b/src/llamafactory/model/patcher.py index a3e2d54b6..f1c7fc8f5 100644 --- a/src/llamafactory/model/patcher.py +++ b/src/llamafactory/model/patcher.py @@ -86,12 +86,9 @@ def _check_fla_dependencies() -> None: def patch_qwen3_5_forward_npu(model: "PreTrainedModel") -> None: - """Patch for Qwen3.5 models on NPU by importing torch_npu to enable torch.cuda compatibility. + """Replace the Qwen3.5 gated delta rule kernel with the NPU-compatible implementation. - On NPU, torch.cuda operations will fail unless torch_npu is imported. - torch_npu provides compatibility layer that maps torch.cuda calls to NPU operations. - - Also replaces chunk_gated_delta_rule with NPU-compatible implementation. + Skip the patch unless an Ascend910-series device is detected and triton_ascend is installed. """ import importlib.metadata