Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

implement ai policy for contributors (#3435)

Edgar Riba240c07863322
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index d34b85e60..8ab82115b 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -6,12 +6,26 @@ This file provides instructions for GitHub Copilot when working with code in thi
Follow the coding standards and best practices defined in [CONTRIBUTING.md](../CONTRIBUTING.md#coding-standards).
-## AI-Generated Content Policy
+## AI Policy
+**CRITICAL**: All contributions must comply with the [AI_POLICY.md](AI_POLICY.md). Review that document for complete requirements.
+
+### Core Principles:
- Code and comments must not be direct, unreviewed outputs of AI agents
- All AI-assisted contributions require human oversight and validation
- Ensure code logic reflects genuine understanding, not copied AI output
+- The submitter is the Sole Responsible Author for every line of code
+
+## Instructions for AI Reviewers (Copilot / CodeRabbit)
+
+AI-based reviewers (e.g. GitHub Copilot, CodeRabbit) must follow the repository's AI usage policy and review rules.
+
+For the complete and authoritative AI reviewer instructions, see [AI_POLICY.md](AI_POLICY.md), section 3.
+When generating or reviewing suggestions, prefer:
+- Enforcing the coding standards in [CONTRIBUTING.md](../CONTRIBUTING.md#coding-standards)
+- Enforcing the AI usage rules and review heuristics defined in [AI_POLICY.md](AI_POLICY.md)
+- Highlighting missing tests, missing proof of local execution, and misuse of `kornia` vs. raw PyTorch utilities
## Key Guidelines
- **Code style**: Follow PEP8, use 120 character line length, Ruff linting, and f-strings
@@ -19,6 +33,7 @@ Follow the coding standards and best practices defined in [CONTRIBUTING.md](../C
- **Documentation**: Follow documentation and docstring guidelines in [CONTRIBUTING.md](../CONTRIBUTING.md#coding-standards) and match the existing codebase style
- **Testing**: Use `BaseTester` pattern with smoke, exception, cardinality, feature, gradcheck, and dynamo tests
- **Dependencies**: Only PyTorch is allowed as a dependency
+- **Use kornia**: Always prefer `kornia` utilities over raw PyTorch functions
## Running Checks
@@ -35,5 +50,9 @@ When reviewing code changes, verify:
- Code and comments are not direct, unreviewed AI agent outputs
- Code follows guidelines in [CONTRIBUTING.md](../CONTRIBUTING.md)
+- Code complies with [AI_POLICY.md](AI_POLICY.md)
- Tests are included for new functionality
- Code passes `pixi run lint` and `pixi run typecheck`
+- PR includes proof of local test execution (test logs)
+- Code uses `kornia` utilities instead of reinventing existing functionality
+- Comments are written in English and verified by a human with a good understanding of the code
diff --git a/AI_POLICY.md b/AI_POLICY.md
new file mode 100644
index 000000000..079ac747c
--- /dev/null
+++ b/AI_POLICY.md
@@ -0,0 +1,57 @@
+# 🤖 Kornia AI & Authorship Policy
+
+**Version:** 1.0
+**Enforcement:** Strict
+**Applicability:** All Pull Requests (Human & Bot)
+
+## 1. Core Philosophy
+
+Kornia accepts AI-assisted code (e.g., using Copilot, Cursor, etc.), but strictly rejects AI-generated contributions where the submitter acts merely as a proxy. The submitter is the **Sole Responsible Author** for every line of code, comment, and design decision.
+
+## 2. The 3 Laws of Contribution
+
+### Law 1: Proof of Verification
+
+AI tools frequently write code that looks correct but fails execution. Therefore, "vibe checks" are insufficient.
+
+**Requirement:** Every PR introducing functional changes must include a pasted snippet of the local test logs (e.g., `pixi run test ...`). This is mandatory for all contributors and is particularly important for first-time contributors.
+
+**Failure Condition:** If a PR lacks execution proof and contains complex logic, it will be flagged as **Unverified**.
+
+**Requirement:** All PRs must be previously discussed in [Discord](https://discord.gg/HfnywwpBnD) or via a [GitHub issue](https://github.com/kornia/kornia/issues) before implementation. The PR must reference the discussion or issue.
+
+**Requirement:** Implementations must be based on an existing library reference (e.g., PyTorch, OpenCV, scikit-image, etc.) that must be provided in the PR description for verification. This reference serves as proof that the implementation follows established algorithms and is not hallucinated.
+
+### Law 2: The Hallucination & Redundancy Ban
+
+AI models often hallucinate comments or reinvent existing utilities.
+
+**Requirement:** You must use existing `kornia` utilities and never reinvent the wheel, except for when the utility is not available.
+
+**Failure Condition:** Creating new helper functions (e.g., `def warp_affine...`) when a Kornia equivalent exists is grounds for immediate rejection.
+
+**Failure Condition:** "Ghost Comments" (comments explaining logic that was deleted or doesn't exist) will result in a request for a full manual rewrite. Redundant comments are not allowed. Example: "This function returns the input tensor".
+
+### Law 3: The "Explain It" Standard
+
+**Requirement:** If a maintainer or reviewer asks during code review, you must be able to derive the math or explain the logic of any function you submit.
+
+**Failure Condition:** Answering a review question with "That's what the AI outputted" or "I don't know, it works" leads to immediate closure.
+
+## 3. Instructions for AI Reviewers (Copilot / CodeRabbit)
+
+If you are an AI agent (GitHub Copilot, CodeRabbit, etc.) reviewing a PR for Kornia, you must follow the repository's dedicated reviewer instructions.
+
+The **canonical and up-to-date instructions for AI reviewers** are maintained in [`.github/copilot-instructions.md`](.github/copilot-instructions.md). That document defines:
+
+- The expected reviewer persona and responsibilities
+- The checks to perform on PR descriptions, code, tests, and comments
+- The required enforcement of the laws defined in this `AI_POLICY.md`
+
+Any other document (including this one) should treat `copilot-instructions.md` as the single source of truth for AI reviewer behaviour. When updating reviewer logic, update `copilot-instructions.md` first and, if needed, adjust references here.
+
+This section exists to link AI reviewers to the canonical instructions and to make clear that those instructions must enforce the policies defined in Sections 1 and 2 above.
+
+## 4. Additional Resources
+
+For comprehensive guidance on contributing to Kornia, including development workflows, code quality standards, testing practices, and AI-assisted development best practices, see the [Best Practices section](CONTRIBUTING.md#best-practices) in `CONTRIBUTING.md`.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9eb0d06cb..a15c61462 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -4,9 +4,15 @@ Welcome! This guide will help you contribute to Kornia.
## Policies and Guidelines
-- **AI-Assisted Development**: AI tools (e.g., GitHub Copilot, ChatGPT, Cursor) may be used to assist with coding, but all contributions must be authored and reviewed by humans. PRs that are fully AI-generated without human understanding, oversight, or ability to explain the code will be rejected. Contributors must understand all code they submit and be able to respond to review feedback.
- - **Automated Detection**: Automated review systems (including GitHub Copilot) analyze PRs for AI-generated content. PRs flagged as having excessive AI-generated content without sufficient human authorship will be rejected. Ensure your contributions reflect genuine human understanding and modification of any AI-assisted code.
+- **AI Policy & Authorship**: See [AI_POLICY.md](AI_POLICY.md) for the complete policy. Summary:
+ - Kornia accepts AI-assisted code but strictly rejects AI-generated contributions where the submitter acts as a proxy.
+ - **Proof of Verification**: PRs must include local test logs proving execution.
+ - **Hallucination & Redundancy Ban**: Use existing `kornia` utilities and never reinvent the wheel, except for when the utility is not available.
+ - **The "Explain It" Standard**: You must be able to explain any code you submit.
+ - Violations result in immediate closure or rejection.
+
- **15-Day Rule**: PRs with no activity for 15+ days will be automatically closed.
+
- **Transparency**: All discussions must be public.
We're all volunteers. These policies help us focus on high-impact work.
@@ -26,9 +32,8 @@ We're all volunteers. These policies help us focus on high-impact work.
3. **Fix bugs or add features:**
- Check [help wanted issues](https://github.com/kornia/kornia/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22help%20wanted%22) for starting points.
- - **PRs must be linked to an issue** (use "Closes #123" or "Fixes #123").
- Follow the [development setup](#developing-kornia) below.
- - Run local tests before submitting.
+ - See [Pull Request](#pull-request) section for PR requirements.
4. **Donate resources:**
- [Open Collective](https://opencollective.com/kornia)
@@ -143,10 +148,6 @@ We're all volunteers. These policies help us focus on high-impact work.
5. **Develop and test:**
- **Requirements:**
- - AI tools may assist with coding, but you must understand and review all code before submission
- - **All local tests must pass before submitting PRs**
-
Create test cases for your code. Run tests with:
```bash
# Run all tests
@@ -174,8 +175,6 @@ We're all volunteers. These policies help us focus on high-impact work.
# Coding Standards
-- Use meaningful names for variables, functions, and classes.
-
- **Write small incremental changes:**
- Commit small, logical changes
- Write clear commit messages
@@ -282,6 +281,8 @@ We're all volunteers. These policies help us focus on high-impact work.
- Follow [PEP8](https://www.python.org/dev/peps/pep-0008/)
- Use f-strings: [PEP 498](https://peps.python.org/pep-0498/)
- Line length: 120 characters
+ - Comments must be written in English and verified by a human with a good understanding of the code
+ - Obvious or redundant comments are not allowed (see [Best Practices](#best-practices) for comment guidelines)
- W504 (line break after binary operator) is sometimes acceptable. Example:
```python
@@ -291,15 +292,100 @@ We're all volunteers. These policies help us focus on high-impact work.
- **Third-party libraries:** Not allowed. Only PyTorch.
+# Best Practices
+
+This section provides guidance for contributing to Kornia, with a focus on Python and PyTorch best practices, performance, and maintainability.
+
+## Before You Start
+
+1. **Discuss First**: Always discuss your proposed changes in Discord or via a GitHub issue before starting implementation. This ensures your work aligns with project goals and avoids duplicate effort.
+
+2. **Start Small**: If you're new to the project, start with small bug fixes or documentation improvements to familiarize yourself with the codebase and contribution process.
+
+3. **Understand the Codebase**: Take time to explore existing code patterns, architecture, and conventions before implementing new features.
+
+4. **Review Existing Utilities**: Before implementing new functionality, search the codebase for existing utilities in `kornia`. This aligns with the AI Policy's Hallucination & Redundancy Ban (see [Policies and Guidelines](#policies-and-guidelines)).
+
+## Development Workflow
+
+1. **Keep PRs Focused**: Each PR should address a single concern. If you're working on multiple features, create separate PRs for each.
+
+2. **Test Locally First**: Always run all relevant tests locally before submitting (see [Pull Request](#pull-request) for requirements):
+ ```bash
+ pixi run lint # Check formatting and linting
+ pixi run test # Run all tests
+ pixi run typecheck # Verify type checking
+ ```
+
+3. **Update Documentation**: When adding new features or changing behavior, update docstrings for public APIs. For documentation contributions, see [Contributing to Documentation](#contributing-to-documentation).
+
+## Code Quality
+
+1. **Performance Considerations**:
+ - Prefer in-place operations when possible (e.g., `tensor.add_(other)` vs `tensor = tensor.add(other)`)
+ - Use tensor views and slicing instead of copying when possible
+ - Leverage PyTorch's vectorized operations over Python loops
+ - Profile before optimizing (use `torch.profiler` or `cProfile`)
+ - Consider memory efficiency for large tensors (use appropriate dtypes, avoid unnecessary copies)
+ - Use `torch.jit.script` or `torch.compile` for performance-critical paths when appropriate
+
+2. **Code Clarity**:
+ - Use descriptive variable and function names that convey intent
+ - Keep functions focused and single-purpose
+ - Prefer clear code over comments; when comments are needed, explain "why" not "what"
+ - Avoid over-engineering; start simple and refactor when needed
+
+3. **Tensor Operations**:
+ - Use `kornia` utilities instead of reimplementing common operations (see [AI Policy](#policies-and-guidelines))
+ - Ensure operations are device-agnostic (work on CPU, CUDA, MPS, etc.)
+ - Support multiple dtypes (float32, float64, float16, bfloat16) when applicable
+ - Handle batched and non-batched inputs consistently
+
+## Testing Best Practices
+
+- Write tests for happy paths, error cases, edge conditions, boundary conditions, and integration scenarios
+- Use `BaseTester` from `testing.base` for consistent test structure (see [Coding Standards](#coding-standards) for examples)
+- Test across different devices and dtypes using pytest parametrization (see [Coding Standards](#coding-standards) for examples)
+- Make tests deterministic, fast, and independent
+- Use descriptive test names; test both forward pass and gradients when applicable
+
+## Review Process
+
+- Review your own PR first: check for typos/formatting, verify tests pass, ensure documentation is updated, and confirm AI policy compliance
+- Respond promptly to review feedback
+- Be open to feedback and explain your decisions when questioned
+- See [Pull Request](#pull-request) section for review requirements
+
+## AI-Assisted Development
+
+- Understand every line of code you submit; you must be able to explain it during review (see [AI Policy](#policies-and-guidelines))
+- Review AI output thoroughly: check for unnecessary complexity, verify it follows project conventions, ensure it uses existing utilities, and test it
+- Be transparent in PR descriptions about what was AI-assisted and what you manually reviewed (see [Pull Request](#pull-request) for AI Usage Disclosure requirements)
+
+## Communication
+
+- Write clear, concise PR descriptions (see [Pull Request](#pull-request) for requirements)
+- Always link to related issues or discussions in your PR description
+- Ask questions in Discord or PR comments if unsure; it's better to clarify early than to rework later
+
# Pull Request
**Requirements:**
- Link PR to an issue (use "Closes #123" or "Fixes #123")
- Pass all local tests before submission
+- Provide proof of local test execution in the PR description (this is especially important for first-time contributors)
+- Fill the [pull request template](.github/pull_request_template.md)
+- **AI Policy Compliance**: Must comply with [AI_POLICY.md](AI_POLICY.md). This includes:
+ - Using existing `kornia` utilities instead of reinventing
+ - Being able to explain all submitted code
+ - Completing the AI Usage Disclosure in the PR template
- 15-Day Rule: Inactive PRs (>15 days) will be closed
-- AI-Assisted Development: AI tools may assist, but PRs must be human-authored and reviewed. Fully AI-generated PRs without human understanding will be rejected. Automated systems (including GitHub Copilot) detect excessive AI-generated content and may reject PRs.
- Transparency: Keep discussions public
+**Code review:**
+- By default, GitHub Copilot will check the PR against the AI Policy and the coding standards.
+- Code must be reviewed by the repository owner or a senior contributor, who have the final say on the quality and acceptance of the PR.
+
**Note:** Tickets may be closed during cleanup. Feel free to reopen if you plan to finish the work.
**CI checks:**
diff --git a/README.md b/README.md
index f4fa4512c..540cb209a 100644
--- a/README.md
+++ b/README.md
@@ -255,6 +255,18 @@ If you are using kornia in your research-related documents, it is recommended th
We appreciate all contributions. If you are planning to contribute back bug-fixes, please do so without any further discussion. If you plan to contribute new features, utility functions or extensions, please first open an issue and discuss the feature with us. Please, consider reading the [CONTRIBUTING](./CONTRIBUTING.md) notes. The participation in this open source project is subject to [Code of Conduct](./CODE_OF_CONDUCT.md).
+### AI Policy
+
+Kornia accepts AI-assisted code but strictly rejects AI-generated contributions where the submitter acts as a proxy. All contributors must be the **Sole Responsible Author** for every line of code. Please review our [AI Policy](AI_POLICY.md) before submitting pull requests. Key requirements include:
+
+- **Proof of Verification**: PRs must include local test logs proving execution
+- **Pre-Discussion**: All PRs must be discussed in Discord or via a GitHub issue before implementation
+- **Library References**: Implementations must be based on existing library references (PyTorch, OpenCV, etc.)
+- **Use Existing Utilities**: Use existing `kornia` utilities instead of reinventing the wheel
+- **Explain It**: You must be able to explain any code you submit
+
+Automated AI reviewers (e.g., GitHub Copilot) will check PRs against these policies. See [AI_POLICY.md](AI_POLICY.md) for complete details.
+
## Community
- **Discord:** Join our workspace to keep in touch with our core contributors, get latest updates on the industry and be part of our community. [JOIN HERE](https://discord.gg/HfnywwpBnD)
- **GitHub Issues:** bug reports, feature requests, install issues, RFCs, thoughts, etc. [OPEN](https://github.com/kornia/kornia/issues/new/choose)
diff --git a/README_zh-CN.md b/README_zh-CN.md
index d9a103bbc..dae77987b 100644
--- a/README_zh-CN.md
+++ b/README_zh-CN.md
@@ -141,6 +141,18 @@
## 贡献
我们感谢所有的贡献者为改进和提升 Kornia 所作出的努力。您可以直接修复一个已知的BUG而无需进一步讨论;如果您想要添加一个任何新的或者扩展功能,请务必先通过提交一个Issue来与我们讨论。详情请阅读 [贡献指南](https://github.com/kornia/kornia/blob/main/CONTRIBUTING.md)。开源项目的参与者请务必了解如下 [规范](https://github.com/kornia/kornia/blob/main/CODE_OF_CONDUCT.md)。
+### AI 政策
+
+Kornia 接受 AI 辅助的代码,但严格拒绝提交者仅作为代理的 AI 生成贡献。所有贡献者必须是每一行代码的**唯一责任作者**。在提交 pull request 之前,请查看我们的 [AI 政策](AI_POLICY.md)。主要要求包括:
+
+- **验证证据**:PR 必须包含本地测试日志以证明代码已执行
+- **事前讨论**:所有 PR 在实施前必须在 Discord 或通过 GitHub issue 进行讨论
+- **库引用**:实现必须基于现有库引用(PyTorch、OpenCV 等)
+- **使用现有工具**:使用现有的 `kornia` 工具,而不是重新发明轮子
+- **解释能力**:您必须能够解释您提交的任何代码
+
+自动化 AI 审查工具(例如 GitHub Copilot)将根据这些政策检查 PR。完整详情请参阅 [AI_POLICY.md](AI_POLICY.md)。
+
## 社区
- **论坛:** 讨论代码实现,学术研究等。[GitHub Forums](https://github.com/kornia/kornia/discussions)
- **GitHub Issues:** bug reports, feature requests, install issues, RFCs, thoughts, etc. [OPEN](https://github.com/kornia/kornia/issues/new/choose)