Strange warning when working with pretrained models

Hi, I’m receiving a series of warnings like the following. I was wondering if it is safe to disregard them? Thanks.
/lib/python3.9/site-packages/pretrainedmodels/models/dpn.py:258: SyntaxWarning: "is" with a literal. Did you mean "=="? elif block_type is 'down':

The warning is raised in the 3rd party lib pretrainedmodels in this line of code:

        if block_type is 'proj':
            self.key_stride = 1
            self.has_proj = True
        elif block_type is 'down':
            self.key_stride = 2
            self.has_proj = True
        else:
            assert block_type is 'normal'
            self.key_stride = 1
            self.has_proj = False

since a str is compared using the “identity” comparison via is instead of the “equality” comparison via ==.
The former checks if the variables are pointing to the exact same object while the latter compares if the variables point at values which are equal.
The repository author might need to fix this, but given the repository wasn’t updated in ~3+ years I doubt the author is still interested in it.

Thank you. What surprises me is that I didn’t get this error before. I’m running the code with the same everything, and now I suddenly got this error. I really am wondering why?

I guess your Python version might have been updated and raises the warning now (rightfully) or maybe you’ve (accidentally) silenced these warnings before somehow. This warning is real but doesn’t depend on any PyTorch-specific code and is raised by plain Python:

if "a" is "b":
    print("c")
# SyntaxWarning: "is" with a literal. Did you mean "=="?
#  if "a" is "b":
1 Like

Got it. Thank you so much for the reply.