[fastcore][fastdot] Fastcore added torch dependency for fastdot

Last night’s release of fastcore (0.1.14) and namely this commit introduced a new dependency on pytorch. Since fastdot depends on fastcore and imports all its dependencies, I cannot anymore use fastdot to write blogposts without having pytorch installed, which seems a bit excessive.

If you install fastdot by itself, though, the torch dependency will not be pulled, but will be requested at runtime.

In my specific case, since I am using JupyterHub, it means that I have either to modify the JupyterHub deployment and add a torch enabled version of the jupyter image (which is doable, but it gets really large) or have to install pytorch every time I restart my server, which takes a long time or I have to persist the installation, which means that the small volume claim that I use needs to get larger to store an unused dependency

EDIT: I am not entirely sure but I think that a possible solution might be wrapping the import statement into a try-except and then putting everything into the compare function. something like.

def equals(a,b):
    "Compares `a` and `b` for equality; supports sublists, tensors and arrays too"
    if one_is_instance(a,b,type): return a==b
    if hasattr(a, '__array_eq__'): return a.__array_eq__(b)
    if hasattr(b, '__array_eq__'): return b.__array_eq__(a)
    cmp = (np.array_equal if one_is_instance(a, b, ndarray       ) else
           operator.eq    if one_is_instance(a, b, (str,dict,set)) else
           all_equal      if is_iter(a) or is_iter(b) else
           operator.eq)
    try:
      import torch
      if one_is_instance(a, b, torch.Tensor): cmp = torch.equals
    except: pass
    return cmp(a,b)

I have no idea what the impact on performance would be though

Sorry, that’s my mistake for merging it. I didn’t remember why we didn’t have that dep.
It’s fine to leave as is as test_eq is only meant to be used with small tensors for unit test. I have reverted the commit and made a new release.

1 Like

Ah sorry, I actually did check if pytorch is already in the package but I just saw import torch in one of the nbs. Did not check if it’s only a dev dependency. I’ll just change my tests.

that was fast! Thanks everyone