8000 [BE] Do not use `numpy` in `torch._inductor.codegen.cpp` by malfet · Pull Request #109324 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[BE] Do not use numpy in torch._inductor.codegen.cpp #109324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions torch/_inductor/codegen/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from copy import copy, deepcopy
from typing import Dict, List

import numpy
import sympy

import torch
Expand Down Expand Up @@ -2155,20 +2154,20 @@ def constant(val, dtype):
# VecKernel override dtype for constant
# Vectorization only support int32/fp32 now
# So if dtype = int64/fp64, we will cast it to int32/fp32 if possible
i32_iinfo = numpy.iinfo(numpy.int32)
i32_iinfo = torch.iinfo(torch.int32)
if (
dtype == torch.int64
and val <= i32_iinfo.max
and val >= i32_iinfo.min
):
opt_ctx.dtype = torch.int32

f32_iinfo = numpy.finfo(numpy.float32)
f32_iinfo = torch.finfo(torch.float32)
if dtype == torch.double:
if (
(val <= f32_iinfo.max and val >= f32_iinfo.min)
or (val == numpy.inf)
or (val == -numpy.inf)
or (val == torch.inf)
or (val == -torch.inf)
):
opt_ctx.dtype = torch.float32

Expand Down Expand Up @@ -2213,7 +2212,7 @@ def can_use_int32():

vars_ranges = {k: ValueRanges(0, v - 1) for k, v in sizes.items()}
if not vars_ranges or len(vars_ranges) != len(free_symbols):
i32_iinfo = numpy.iinfo(numpy.int32)
i32_iinfo = torch.iinfo(torch.int32)
return (
expr.is_number
and expr <= i32_iinfo.max
Expand Down
0