TypeError when executing plot_function

When running this code :

from ipywidgets import interact
from fastai.basics import *

@interact(a=1.5, b=1.5, c=1.5)
def plot_quad(a, b, c):
    f = mk_quad(a, b, c)
    loss = mse(f(x), y)
    plot_function(f, ylim=(-3,12), title=f"MSE: {loss:.2f}")

which this plot_function -

def plot_function(f, title=None, min=-2.1, max=2.1, color='r', ylim=None):
    x = torch.linspace(min,max, 100)[:,None]
    if ylim:
    plt.plot(x, f(x), color)
    if title is not None:

def f(x):
    return 3*x**2 + 2*x + 1

I ran into this error –

TypeError                                 Traceback (most recent call last)
File ~/.virtualenvs/fastai23/lib/python3.10/site-packages/ipywidgets/widgets/interaction.py:257, in interactive.update(self, *args)
    255     value = widget.get_interact_value()
    256     self.kwargs[widget._kwarg] = value
--> 257 self.result = self.f(**self.kwargs)
    258 show_inline_matplotlib_plots()
    259 if self.auto_display and self.result is not None:

Cell In[13], line 9, in plot_quad(a, b, c)
      7 plt.scatter(x,y)
      8 loss = mse(f(x), y)
----> 9 plot_function(f, ylim=(-3,12), title=f"MSE: {loss:.2f}")

File ~/.virtualenvs/fastai23/lib/python3.10/site-packages/torch/_tensor.py:870, in Tensor.__format__(self, format_spec)
    868 def __format__(self, format_spec):
    869     if has_torch_function_unary(self):
--> 870         return handle_torch_function(Tensor.__format__, (self,), self, format_spec)
    871     if self.dim() == 0 and not self.is_meta and type(self) is Tensor:
    872         return self.item().__format__(format_spec)

File ~/.virtualenvs/fastai23/lib/python3.10/site-packages/torch/overrides.py:1551, in handle_torch_function(public_api, relevant_args, *args, **kwargs)
   1545     warnings.warn("Defining your `__torch_function__ as a plain method is deprecated and "
   1546                   "will be an error in future, please define it as a classmethod.",
   1547                   DeprecationWarning)
   1549 # Use `public_api` instead of `implementation` so __torch_function__
   1550 # implementations can do equality/identity comparisons.
-> 1551 result = torch_func_method(public_api, types, args, kwargs)
   1553 if result is not NotImplemented:
   1554     return result

File ~/FASTAI23/fastai/fastai/torch_core.py:382, in TensorBase.__torch_function__(cls, func, types, args, kwargs)
    380 if cls.debug and func.__name__ not in ('__str__','__repr__'): print(func, types, args, kwargs)
    381 if _torch_handled(args, cls._opt, func): types = (torch.Tensor,)
--> 382 res = super().__torch_function__(func, types, args, ifnone(kwargs, {}))
    383 dict_objs = _find_args(args) if args else _find_args(list(kwargs.values()))
    384 if issubclass(type(res),TensorBase) and dict_objs: res.set_meta(dict_objs[0],as_copy=True)

File ~/.virtualenvs/fastai23/lib/python3.10/site-packages/torch/_tensor.py:1295, in Tensor.__torch_function__(cls, func, types, args, kwargs)
   1292     return NotImplemented
   1294 with _C.DisableTorchFunctionSubclass():
-> 1295     ret = func(*args, **kwargs)
   1296     if func in get_default_nowrap_functions():
   1297         return ret

File ~/.virtualenvs/fastai23/lib/python3.10/site-packages/torch/_tensor.py:873, in Tensor.__format__(self, format_spec)
    871 if self.dim() == 0 and not self.is_meta and type(self) is Tensor:
    872     return self.item().__format__(format_spec)
--> 873 return object.__format__(self, format_spec)

TypeError: unsupported format string passed to TensorBase.__format__

I have no clue what’s the problem, but seems like PyTorch doesn’t seem to support formatted string.

But then, wondering how this thing is not reported before, is it only me !

any assistance is gratefully appreciated !

I an running on my own box running

(fastai23) $ python -c "import fastai; print(fastai.__version__)"
(fastai23) $ python -c "import torch; print(torch.cuda.is_available())"
(fastai23) $ python -c "import torchvision; print(torchvision.__version__)"
(fastai23) $