PyTorch Memory Not Automatically Pinned
Description
If possible, it is better to rely on automatic pinning in PyTorch to avoid undefined behavior and for efficiency. PyTorch memory not automatically pinned.
Examples
Insecure Code
python
torch.utils.data.DataLoader(dataset, batch_size=32)Secure Code
python
torch.utils.data.DataLoader(dataset, batch_size=32, pin_memory=True)Remediation
Use the `pin_memory=True` argument when creating a `DataLoader` to enable automatic memory pinning.
Rule Details
| Field | Value |
|---|---|
| ID | CODE-0640 |
| Category | InsecureConfig |
| Severity | LOW |
| CWE | CWE-676 |
| Confidence | HIGH |
| Impact | LOW |
| Likelihood | LOW |
| Exploitability | COMPLEX |
| Tags | memory-pinning, pytorch |
| OWASP | N/A |