Repository: wandb/wandb

Issue:
Add Native Support for Fastai Tensor Types
[fastai](https://github.com/fastai/fastai) extends PyTorch's tensors to have custom data types like `TensorCategory`, etc. I'm not sure how exactly the WandbCallback for fastai works but I assume it converts them to PyTorch tensors when passing it to Wandb's JSONEncoders.

Do you think it makes sense to add native support for this? It would require modifying `wandb/util.py` like so:
```python
def is_fastai_tensor_typename(typename):
    # restrict to TensorCategory and TensorMultiCategory?
    return typename.startswith('fastai') and 'Tensor' in typename

def json_friendly(obj):
    ...
    elif is_pytorch_tensor_typename(typename) or is_fastai_tensor_typename(typename):
    ...
```




Discussion:
Issue-Label Bot is automatically applying the label `feature_request` to this issue, with a confidence of 0.94. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback! 

 Links: [app homepage](https://github.com/marketplace/issue-label-bot), [dashboard](https://mlbot.net/data/wandb/client) and [code](https://github.com/hamelsmu/MLapp) for this bot.
@vanpelt can you please take a look here?
@borisdayma is this something we can add easily?
Probably!

@rsomani95 The fastai tensors are not converted to Pytorch tensors but could be logged in my tests.
Are you trying to log images or something else? Do you have a colab so I understand better the issue you are having?

Also should we try to close the related fastai issue first?
@borisdayma I was actually only trying to use the standard W&B callback with the PyTorch 1.8 nightly version. Not trying to log anything extra.

After making the changes mentioned in the related fastai issue -- specifically commenting out `_patch_tb()` [here](https://github.com/fastai/fastai/blob/8f8c629bd2da69a5d4b0d2dbb053ce5c0aa29180/fastai/torch_core.py#L324), I ran into the tensor type conversion issue which I was able to bypass making the changes I proposed above.

However, using the fastai W&B callback now leads to a python multiprocessing error that I'm not sure how to debug, so I decided to stop hacking around and let the official versions release. 

I do not have a colab notebook for you to try out. Is the description above specific enough? It's tricky to reproduce because I've made modifications to both fastai and w&b source. LMK if you plan on tackling this and how I can be of better help.



> Also should we try to close the related fastai issue first?

Sure! I'm just not sure how to proceed


EDIT: I can reproduce my steps in an isolated environment and post the specific error messages here

Resolving patch:
diff --git a/wandb/util.py b/wandb/util.py
--- a/wandb/util.py
+++ b/wandb/util.py
@@ -287,6 +287,10 @@ def is_pytorch_tensor_typename(typename):
     )
 
 
+def is_fastai_tensor_typename(typename):
+    return typename.startswith("fastai.") and ("Tensor" in typename)
+
+
 def is_pandas_data_frame_typename(typename):
     return typename.startswith("pandas.") and "DataFrame" in typename
 
@@ -382,7 +386,7 @@ def json_friendly(obj):
             obj = obj.eval()
         except RuntimeError:
             obj = obj.numpy()
-    elif is_pytorch_tensor_typename(typename):
+    elif is_pytorch_tensor_typename(typename) or is_fastai_tensor_typename(typename):
         try:
             if obj.requires_grad:
                 obj = obj.detach()


Test patch: