本页面概述了 Keras 3 的开发流程和贡献指南。它涵盖了如何设置开发环境、理解项目结构、运行测试以及向 Keras 项目贡献代码。有关依赖项管理的具体详情,请参阅依赖项管理;有关测试和 CI/CD 系统,请参阅测试和 CI/CD;有关详细的贡献指南,请参阅贡献指南。
Keras 提供了两种主要的开发环境设置方法:使用 GitHub Codespaces/开发容器或配置本地环境。
Keras 支持 GitHub Codespaces、Visual Studio Code 开发容器和 JetBrains 开发容器,以提供一致的开发体验,无需手动设置。
要设置本地开发环境,您需要
基本设置过程包括
对于 GPU 支持,您需要安装特定后端的依赖项
pip install -r requirements-tensorflow-cuda.txtpip install -r requirements-jax-cuda.txtpip install -r requirements-torch-cuda.txt来源:CONTRIBUTING.md66-108 requirements.txt1-24 requirements-tensorflow-cuda.txt1-13 requirements-jax-cuda.txt1-15 requirements-torch-cuda.txt1-16
Keras 使用预提交钩子来维护代码质量并自动生成 API 文件。首次设置存储库时,请运行
当您提交更改时,会自动执行三个过程
如果其中任何一个过程失败,提交将被拒绝。您需要修复问题并重试。
要在所有文件上手动运行这些钩子
API 生成过程会创建公共 Keras API 和 TensorFlow 兼容层。
来源:CONTRIBUTING.md110-140 .pre-commit-config.yaml1-25 shell/api_gen.sh1-14
Keras 使用 pytest 运行测试。测试按后端组织,每个后端的实现都有特定的测试。
Keras 测试在多个后端(TensorFlow、JAX、PyTorch、NumPy、OpenVINO)上运行,以确保兼容性。
来源:.github/workflows/actions.yml1-109 .github/workflows/nightly.yml1-123
Keras 具有集成测试,以验证该包是否可以在不同后端上正确安装和使用。
来源:integration_tests/import_test.py1-130 integration_tests/basic_full_flow.py1-55
Keras 还拥有用于在 GPU 环境中进行测试的特定基础设施,以确保高性能兼容性。
来源:.kokoro/github/ubuntu/gpu/build.sh1-80
贡献流程遵循以下关键步骤
来源:CONTRIBUTING.md10-64 .github/workflows/actions.yml110-139
Keras 遵循特定的文档字符串约定
Examples 部分Args 部分Call arguments、Returns 和可选的 Raises 部分Examples 部分Args 部分Returns 部分Raises 部分Keras 使用 GitHub 的问题跟踪系统,并采用自动化流程进行问题管理。
来源:.github/workflows/stale-issue-pr.yaml1-56 .github/workflows/auto-assignment.yaml1-21 .github/workflows/scripts/auto-assignment.js1-61
Keras 通过多个需求文件管理依赖项
requirements.txt - 所有后端的主要依赖项requirements-common.txt - 跨后端的通用依赖项requirements-tensorflow-cuda.txt - 支持 GPU 的 TensorFlowrequirements-jax-cuda.txt - 支持 GPU 的 JAXrequirements-torch-cuda.txt - 支持 GPU 的 PyTorchrequirements-openvino.txt - OpenVINO 依赖项有关依赖项管理的更多详细信息,请参阅依赖项管理。
来源:requirements.txt1-24 requirements-tensorflow-cuda.txt1-13 requirements-jax-cuda.txt1-15 requirements-torch-cuda.txt1-16
Keras 使用延迟模块加载系统来高效处理可选依赖项。这种模式允许 Keras 仅在需要时才导入模块,并在依赖项缺失时提供有用的错误消息。
该系统用于处理 TensorFlow、JAX、PyTorch XLA 和 scipy 等可选依赖项。
来源:keras/src/utils/module_utils.py1-61
Keras 开发和贡献生态系统旨在支持具有强大测试和质量保证的多后端深度学习框架。该项目采用了现代 CI/CD 实践、用于代码质量的预提交钩子,以及跨多个后端和硬件配置的全面测试。
有关更多具体信息,请参阅