ruff: suppressible-exception (#5182)

* fix: use contextlib to suppress errors

* enable rule SIM105

---------

Co-authored-by: George Hotz <72895+geohot@users.noreply.github.com>
This commit is contained in:
Roelof van Dijk
2024-06-27 17:23:44 +02:00
committed by GitHub
parent 9704c7d4d4
commit 01e8838b65
3 changed files with 5 additions and 8 deletions

View File

@@ -27,6 +27,7 @@ lint.select = [
"RET506", # superfluous-else-raise
"RET507", # superfluous-else-continue
"A", # builtin-variable-shadowing, builtin-argument-shadowing, builtin-attribute-shadowing
"SIM105", # suppressible-exception
"FURB110",# if-exp-instead-of-or-operator
]

View File

@@ -1,4 +1,4 @@
import os, atexit, functools
import os, atexit, functools, contextlib
from collections import defaultdict
from typing import List, Any, DefaultDict, Union
from tinygrad.ops import UnaryOps, BinaryOps, ReduceOps, LoadOps, BufferOps, TernaryOps, LazyOp
@@ -8,8 +8,7 @@ from tinygrad.codegen.uops import UOps, UOp, UPat
from tinygrad.shape.symbolic import NumNode
from tinygrad.lazy import LazyBuffer
try: import networkx as nx
except ImportError: pass
with contextlib.suppress(ImportError): import networkx as nx
# **** debugging and graphing ****

View File

@@ -1,5 +1,5 @@
from __future__ import annotations
import os, ctypes, pathlib, re, fcntl, functools, mmap, struct, tempfile, hashlib, subprocess, time, array
import os, ctypes, contextlib, pathlib, re, fcntl, functools, mmap, struct, tempfile, hashlib, subprocess, time, array
from typing import Tuple, List, Any
from dataclasses import dataclass
from tinygrad.device import HCQCompatCompiled, HCQCompatAllocator, Compiler, CompileError, BufferOptions
@@ -458,10 +458,7 @@ class NVDevice(HCQCompatCompiled):
fd_uvm_2 = os.open("/dev/nvidia-uvm", os.O_RDWR | os.O_CLOEXEC)
NVDevice.root = rm_alloc(self.fd_ctl, nv_gpu.NV01_ROOT_CLIENT, 0, 0, None).hObjectNew
uvm.initialize(self.fd_uvm)
try:
uvm.mm_initialize(fd_uvm_2, uvmFd=self.fd_uvm)
except RuntimeError:
pass # this error is okay, CUDA hits it too
with contextlib.suppress(RuntimeError): uvm.mm_initialize(fd_uvm_2, uvmFd=self.fd_uvm) # this error is okay, CUDA hits it too
NVDevice.gpus_info = (nv_gpu.nv_ioctl_card_info_t*64)()
nv_iowr(NVDevice.fd_ctl, nv_gpu.NV_ESC_CARD_INFO, NVDevice.gpus_info)