You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Type of change:** ? <!-- Use one of the following: Bug fix, new feature, new example, new tests, documentation. -->
3
+
Type of change: ? <!-- Use one of the following: Bug fix, new feature, new example, new tests, documentation. -->
4
4
5
-
**Overview:** ?
5
+
<!-- More details about the change. -->
6
6
7
-
## Usage
8
-
<!-- You can potentially add a usage example below. -->
7
+
### Usage
9
8
10
9
```python
11
10
# Add a code snippet demonstrating how to use this
12
11
```
13
12
14
-
## Testing
13
+
###Testing
15
14
<!-- Mention how have you tested your change if applicable. -->
16
15
17
-
## Before your PR is "*Ready for review*"
18
-
<!-- If you haven't finished some of the above items you can still open `Draft` PR. -->
16
+
### Before your PR is "*Ready for review*"
19
17
20
-
-**Make sure you read and follow [Contributor guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)** and your commits are signed.
21
-
-**Is this change backward compatible?**: Yes/No <!--- If No, explain why. -->
22
-
-**Did you write any new necessary tests?**: Yes/No
23
-
-**Did you add or update any necessary documentation?**: Yes/No
24
-
-**Did you update [Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?**: Yes/No <!--- Only for new features, API changes, critical bug fixes or bw breaking changes. -->
18
+
Make sure you read and follow [Contributor guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md) and your commits are signed (`git commit -s -S`).
25
19
26
-
## Additional Information
20
+
Make sure you read and follow the [Security Best Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors) (e.g. hardcoded `trust_remote_code=True`, `torch.load(..., weights_only=True)`, `pickle`, etc.).
21
+
22
+
- Is this change backward compatible?: ✅❌ <!--- If ❌, explain why. -->
23
+
- If you copied code from any other source, did you follow IP policy in [CONTRIBUTING.md](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md#-copying-code-from-other-sources)?: ✅❌ <!--- Mandatory -->
24
+
- Did you write any new necessary tests?: ✅❌ <!--- Mandatory for new features or examples. -->
25
+
- Did you add or update any necessary documentation and update [Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?: ✅❌ <!--- Only for new features, API changes, critical bug fixes or backward incompatible changes. -->
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+36-21Lines changed: 36 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,36 +39,45 @@ To run the pre-commit hooks without committing, use:
39
39
pre-commit run --all-files
40
40
```
41
41
42
-
## 📝 Writing tests
42
+
## 🔒 Security coding practices
43
43
44
-
We use [pytest](https://docs.pytest.org/) for all tests. The tests are organized into the following directories:
44
+
All contributors must follow the security coding practices documented in our
45
+
[SECURITY.md](./SECURITY.md#security-coding-practices-for-contributors) page (see the *Security Coding Practices for
46
+
Contributors* section). These rules cover a few key security considerations like:
45
47
46
-
-`tests/unit`: Fast cpu-based unit tests for the core ModelOpt library. They should not take more than a few seconds to run.
47
-
-`tests/gpu`: Fast GPU-based unit tests for the core ModelOpt library. In most cases, they should not take more than a few seconds to run.
48
-
-`tests/examples`: Integration tests for ModelOpt examples. They should not take more than a few minutes to run. Please refer to [example test README](./tests/examples/README.md) for more details.
48
+
-Safe use of `torch.load`, `numpy.load`, and `yaml.load`
49
+
-Hardcoded `trust_remote_code=True` flag for transformers model loading
50
+
-Subprocess and shell command safety
49
51
50
-
Please refer to [tox.ini](./tox.ini) for more details on how to run the tests and their dependencies.
52
+
Any security-sensitive exception requires review and approval from `@NVIDIA/modelopt-setup-codeowners`.
51
53
52
-
### Code Coverage
54
+
##📋 Copying code from other sources
53
55
54
-
For any new features / examples, make sure to they are covered by the tests and that the Codecov coverage check in your PR passes.
56
+
The utilization of third-party code requires authorization via the Open Source Review Board (OSRB) team and needs to follow proper guidance on contributing code.
55
57
56
-
## Submitting your code
58
+
If you are an external contributor, seek guidance from `@NVIDIA/modelopt-setup-codeowners` for next steps. For internal contributors, follow the steps below:
57
59
58
-
- If you are an external contributor, create a fork of the repository.
59
-
- Rebase (not merge) your code to the most recent commit of the `main` branch. We want to ensure a linear history;
60
-
see [Merge vs Rebase](https://www.atlassian.com/git/tutorials/merging-vs-rebasing). Remember to test again locally after rebasing to catch any new issues before pushing to your PR.
60
+
-**File NVBug for use of open source code:**
61
+
Clone NVBug 2885977 and add your use case. Copying code from permissive licensed repositories (e.g. MIT, Apache 2) is generally self-checkout but for other licenses, it is necessary to get expert guidance before merging your PR.
62
+
-**License header format:** The file which has code copied from another third-party GitHub repository should have the following in order:
63
+
1. A reference link (with commit hash) to the source from which the code was copied.
64
+
1. The original repository's Copyright / License.
65
+
1. The NVIDIA Apache 2.0 Copyright / License header.
61
66
62
-
```bash
63
-
git pull
64
-
git rebase origin/main
65
-
git push origin <branch> --force-with-lease
66
-
```
67
+
See [`modelopt/torch/speculative/eagle/utils.py`](./modelopt/torch/speculative/eagle/utils.py)
68
+
for an example of the correct license header format.
69
+
-**Exclude from license pre-commit hook:** Exclude copied files from the license pre-commit hook so it doesn't auto-add the NVIDIA Apache 2.0 license on top of the file. Add the file path to the `exclude` list in the `insert-license` hook in [`.pre-commit-config.yaml`](./.pre-commit-config.yaml).
67
70
68
-
- When pushing the rebased (or any) branch, use `git push --force-with-lease` instead of `git push --force`.
69
-
- Submit a pull request and let auto-assigned reviewers (based on [CODEOWNERS](./.github/CODEOWNERS)) review your PR.
70
-
- If any CI/CD checks fail, fix the issues and push again.
71
-
- Once your PR is approved and all checks pass, one of the reviewers will merge the PR.
71
+
## 📝 Writing tests
72
+
73
+
We use [pytest](https://docs.pytest.org/) for all tests. For any new features / examples, make sure to add tests and that the coverage check in your PR passes. The tests are organized into the following directories:
74
+
75
+
-`tests/unit`: Fast cpu-based unit tests for the core ModelOpt library. They should not take more than a few seconds to run.
76
+
-`tests/gpu`: Fast GPU-based unit tests for the core ModelOpt library. In most cases, they should not take more than a few seconds to run.
77
+
-`tests/gpu_megatron`: Fast GPU-based unit tests for the core ModelOpt library for Megatron-Core features. In most cases, they should not take more than a few seconds to run.
78
+
-`tests/examples`: Integration tests for ModelOpt examples. They should not take more than a few minutes to run. Please refer to [example test README](./tests/examples/README.md) for more details.
79
+
80
+
Please refer to [tox.ini](./tox.ini) for more details on how to run the tests and their dependencies.
(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
137
146
```
147
+
148
+
## Submitting your code
149
+
150
+
- Submit a pull request and let auto-assigned reviewers (based on [CODEOWNERS](./.github/CODEOWNERS)) review your PR.
151
+
- If any CI/CD checks fail, fix the issues and push again.
152
+
- Once your PR is approved and all checks pass, one of the reviewers will merge the PR.
Copy file name to clipboardExpand all lines: SECURITY.md
+147-1Lines changed: 147 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,4 +22,150 @@ While NVIDIA currently does not have a bug bounty program, we do offer acknowled
22
22
23
23
## NVIDIA Product Security
24
24
25
-
For all security-related concerns, please visit NVIDIA's [Product Security portal](https://www.nvidia.com/en-us/security)
25
+
For all security-related concerns, please visit NVIDIA's [Product Security portal](https://www.nvidia.com/en-us/security).
26
+
27
+
---
28
+
29
+
## Security Considerations
30
+
31
+
### Overview
32
+
33
+
NVIDIA Model Optimizer (ModelOpt) is a library used to optimize ML models and may load and process user-provided artifacts (models, weights, configs, calibration data) and their dependencies. Secure deployment depends on how you source artifacts, validate inputs, and harden the environment where ModelOpt runs.
34
+
35
+
### What to Be Aware Of
36
+
37
+
#### Untrusted model and data inputs
38
+
39
+
- Models, weights, configs and data may be malicious or corrupted.
40
+
41
+
#### Deserialization and code-execution risks
42
+
43
+
- Unsafe deserialization can lead to arbitrary code execution if fed untrusted inputs.
44
+
- Avoid using serialization formats/settings that can deserialize arbitrary objects.
45
+
46
+
#### Input validation and resource exhaustion
47
+
48
+
- Large or malformed inputs can trigger crashes or excessive CPU/GPU/memory use.
49
+
- Missing size/type checks can increase DoS risk.
50
+
51
+
#### Data in transit and at rest
52
+
53
+
- If fetching models or dependencies over the network, insecure transport can enable tampering.
54
+
- Stored artifacts, logs, and caches may contain sensitive data.
55
+
56
+
#### Logging and observability
57
+
58
+
- Logs may inadvertently contain sensitive inputs, paths, tokens, or proprietary model details.
59
+
- Overly verbose logs can leak operational and security-relevant information.
60
+
61
+
#### Supply chain and third-party components
62
+
63
+
- Dependencies may include known vulnerabilities or be compromised.
64
+
- Third-party plugins/components loaded at runtime may not have the same security assurances.
65
+
66
+
### Example Security Approaches
67
+
68
+
#### Artifact integrity
69
+
70
+
- Only load artifacts from trusted sources.
71
+
- Prefer signed artifacts; verify signatures before loading.
- Keep OS, containers, and dependencies patched; scan for known vulnerabilities.
92
+
93
+
---
94
+
95
+
## Security Coding Practices for Contributors
96
+
97
+
ModelOpt processes model checkpoints and weights from various sources. Contributors must avoid patterns that can introduce security vulnerabilities. These rules apply to all code except tests. These rules cover a few key security considerations as follows:
98
+
99
+
### Deserializing untrusted data
100
+
101
+
**`torch.load` should not be used with `weights_only=False`** unless there is a documented reason why it cannot. It uses pickle under the hood and can execute arbitrary code from a malicious checkpoint.
102
+
103
+
```python
104
+
# Bad — allows arbitrary code execution from the checkpoint file
105
+
state = torch.load(path, weights_only=False)
106
+
107
+
# Good
108
+
state = torch.load(path, weights_only=True, map_location="cpu")
109
+
110
+
# Acceptable only with an inline comment explaining why weights_only=False
111
+
# is required and confirming the file is internally-generated / trusted.
112
+
state = torch.load(
113
+
path,
114
+
weights_only=False, # loaded file is generated internally by ModelOpt and not supplied by the user
115
+
map_location="cpu",
116
+
)
117
+
```
118
+
119
+
**`numpy.load` should not be used with `allow_pickle=True`** unless there is a documented reason why it cannot. It uses pickle under the hood and can execute arbitrary code from a malicious checkpoint.
120
+
121
+
```python
122
+
# Bad — allows arbitrary code execution from the checkpoint file
123
+
state = numpy.load(path, allow_pickle=True)
124
+
125
+
# Good - let the caller decide; default to False
126
+
defload_data(path: str, trust_data: bool=False):
127
+
return numpy.load(path, allow_pickle=trust_data)
128
+
```
129
+
130
+
**Do not use `yaml.load()`** — always use `yaml.safe_load()`. The default loader can execute arbitrary Python objects embedded in YAML.
131
+
132
+
### Loading transformers models with `trust_remote_code`
133
+
134
+
**Do not hardcode `trust_remote_code=True`.** This flag tells Transformers to execute arbitrary Python shipped with a checkpoint, which is an RCE vector if the model source is untrusted.
135
+
136
+
```python
137
+
# Bad — silently opts every user into remote code execution
138
+
model = AutoModel.from_pretrained(name, trust_remote_code=True)
-**`eval()` / `exec()`** on strings derived from external input. If you must generate and execute code dynamically, validate the input against an allowlist of safe patterns.
160
+
-**Hardcoded secrets or credentials** — never commit tokens, passwords, or API keys. Use environment variables or config files listed in `.gitignore`.
161
+
162
+
### Bandit security checks
163
+
164
+
Bandit is used as a pre-commit hook to check for security-sensitive patterns in the code. **`# nosec` comments are not allowed** as a bypass for security checks.
165
+
166
+
### Creating a security exception
167
+
168
+
If a security-sensitive pattern (e.g. `pickle`, `subprocess`) is genuinely required, the contributor must:
169
+
170
+
1.**Add an inline comment** explaining *why* the pattern is necessary and *why* it is safe in this specific context (e.g. "loaded file is generated internally by ModelOpt").
171
+
1.**Request review from [@NVIDIA/modelopt-setup-codeowners](https://github.com/orgs/NVIDIA/teams/modelopt-setup-codeowners)** and include a clear justification in the PR description.
0 commit comments