Thursday, 28 August 2025

torch.cuda.is_available() is False. But why?

[blogger doesn't support markdown eh?  Might be time for a new hosting service] 

 

 `torch.cuda.is_available()` will tell you if you have CUDA set up right.  But doesn't tell you why it's not working.

TIL, per stackoverflow, if you instead run:
`a=torch.cuda.FloatTensor()`

You get a useful error message.

```
> python
Python 3.11.13 (main, Aug 18 2025, 19:14:35) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> a = torch.cuda.FloatTensor()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type torch.cuda.FloatTensor not available. Torch not compiled with CUDA enabled.
>>>
```

Monday, 25 August 2025

TIL Python: f"hello {thing!r}"

 When formatting strings in Python, you can use a suffix to run a conversion on it:

Three conversion flags are currently supported: '!s' which calls str() on the value, '!r' which calls repr() and '!a' which calls ascii().

Some examples:

"Harold's a clever {0!s}"        # Calls str() on the argument first
"Bring out the holy {name!r}"    # Calls repr() on the argument first
"More {!a}"                      # Calls ascii() on the argument first

 I ran into it while reading tiktoken/core.py:

    def __repr__(self) -> str:

        return f"<Encoding {self.name!r}>"