Optimize int precision
MEMBER
@lhoestq, are the tests OK? Some other cases I missed? Do you agree with this approach?
2021-03-04T14:15:02Z
https://github.com/huggingface/datasets/pull/1985#issuecomment-790647873
https://api.github.com/repos/huggingface/datasets/issues/1985
MDEyOklzc3VlQ29tbWVudDc5MDY0Nzg3Mw==
https://api.github.com/repos/huggingface/datasets/issues/comments/790647873/reactions
2021-03-04T14:15:02Z
https://api.github.com/repos/huggingface/datasets/issues/comments/790647873
https://avatars.githubusercontent.com/u/8515462?v=4
https://api.github.com/users/albertvillanova/events{/privacy}
https://api.github.com/users/albertvillanova/followers
https://api.github.com/users/albertvillanova/following{/other_user}
https://api.github.com/users/albertvillanova/gists{/gist_id}
https://github.com/albertvillanova
albertvillanova
MDQ6VXNlcjg1MTU0NjI=
https://api.github.com/users/albertvillanova/orgs
https://api.github.com/users/albertvillanova/received_events
https://api.github.com/users/albertvillanova/repos
https://api.github.com/users/albertvillanova/starred{/owner}{/repo}
https://api.github.com/users/albertvillanova/subscriptions
User
https://api.github.com/users/albertvillanova
public
MEMBER
I just tested this and it works like a charm :) 

However tokenizing and then setting the format to "torch" to feed the tokens into a model doesn't seem to work anymore, since the pytorch tensors have the int32/int8 precisions instead of int64 that is required as model inputs.

For example:

```python
import torch
from datasets import Dataset
from transformers import BertModel, BertTokenizer

torch.set_grad_enabled(False)

tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
model = BertModel.from_pretrained("bert-base-uncased")

dataset = Dataset.from_dict({"text": ["hello there !"]})
dataset = dataset.map(tokenizer, input_columns="text", remove_columns=dataset.column_names)
dataset = dataset.with_format("torch")

print(dataset.features)
# {'attention_mask': Sequence(feature=Value(dtype='int8', id=None), length=-1, id=None),
#  'input_ids': Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None),  # this should be int32 though
#  'token_type_ids': Sequence(feature=Value(dtype='int8', id=None), length=-1, id=None)}

model(**dataset[:1])
# RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.CharTensor instead (while checking arguments for embedding)

dataset = dataset.with_format("torch", dtype=torch.int64)

model(**dataset[:1])
# works as expected
```

Pinging @sgugger here to make sure we take the right decision here.

Do we want the "torch" format to always return int64 ? Or does it have to keep the precision defined by the `dataset.features` 
 and therefore we would need to specify "torch" with `dtype=torch.int64` ?
2021-03-11T14:27:01Z
https://github.com/huggingface/datasets/pull/1985#issuecomment-796775248
https://api.github.com/repos/huggingface/datasets/issues/1985
MDEyOklzc3VlQ29tbWVudDc5Njc3NTI0OA==
https://api.github.com/repos/huggingface/datasets/issues/comments/796775248/reactions
2021-03-11T14:28:25Z
https://api.github.com/repos/huggingface/datasets/issues/comments/796775248
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
From a user perspective, I think it's fine if the "torch" format converts all ints types to `torch.int64` by default since it's what the model will need almost all the time. I don't see a case where you would want to keep the low precision at the top of my head, and one can always write a custom transform for an edge case.
2021-03-11T15:30:10Z
https://github.com/huggingface/datasets/pull/1985#issuecomment-796820538
https://api.github.com/repos/huggingface/datasets/issues/1985
MDEyOklzc3VlQ29tbWVudDc5NjgyMDUzOA==
https://api.github.com/repos/huggingface/datasets/issues/comments/796820538/reactions
2021-03-11T15:30:10Z
https://api.github.com/repos/huggingface/datasets/issues/comments/796820538
https://avatars.githubusercontent.com/u/35901082?v=4
https://api.github.com/users/sgugger/events{/privacy}
https://api.github.com/users/sgugger/followers
https://api.github.com/users/sgugger/following{/other_user}
https://api.github.com/users/sgugger/gists{/gist_id}
https://github.com/sgugger
sgugger
MDQ6VXNlcjM1OTAxMDgy
https://api.github.com/users/sgugger/orgs
https://api.github.com/users/sgugger/received_events
https://api.github.com/users/sgugger/repos
https://api.github.com/users/sgugger/starred{/owner}{/repo}
https://api.github.com/users/sgugger/subscriptions
User
https://api.github.com/users/sgugger
public
MEMBER
Sounds good to me !
For consistency maybe we should make the float precision fixed as well (float32, I guess)
2021-03-11T15:45:51Z
https://github.com/huggingface/datasets/pull/1985#issuecomment-796831883
https://api.github.com/repos/huggingface/datasets/issues/1985
MDEyOklzc3VlQ29tbWVudDc5NjgzMTg4Mw==
https://api.github.com/repos/huggingface/datasets/issues/comments/796831883/reactions
2021-03-11T15:45:51Z
https://api.github.com/repos/huggingface/datasets/issues/comments/796831883
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
Yes, that would be the one used by default.
2021-03-11T16:13:13Z
https://github.com/huggingface/datasets/pull/1985#issuecomment-796852642
https://api.github.com/repos/huggingface/datasets/issues/1985
MDEyOklzc3VlQ29tbWVudDc5Njg1MjY0Mg==
https://api.github.com/repos/huggingface/datasets/issues/comments/796852642/reactions
2021-03-11T16:13:13Z
https://api.github.com/repos/huggingface/datasets/issues/comments/796852642
https://avatars.githubusercontent.com/u/35901082?v=4
https://api.github.com/users/sgugger/events{/privacy}
https://api.github.com/users/sgugger/followers
https://api.github.com/users/sgugger/following{/other_user}
https://api.github.com/users/sgugger/gists{/gist_id}
https://github.com/sgugger
sgugger
MDQ6VXNlcjM1OTAxMDgy
https://api.github.com/users/sgugger/orgs
https://api.github.com/users/sgugger/received_events
https://api.github.com/users/sgugger/repos
https://api.github.com/users/sgugger/starred{/owner}{/repo}
https://api.github.com/users/sgugger/subscriptions
User
https://api.github.com/users/sgugger
public
MEMBER
Do we have the same requirements for TensorFlow?
2021-03-11T16:34:07Z
https://github.com/huggingface/datasets/pull/1985#issuecomment-796869230
https://api.github.com/repos/huggingface/datasets/issues/1985
MDEyOklzc3VlQ29tbWVudDc5Njg2OTIzMA==
https://api.github.com/repos/huggingface/datasets/issues/comments/796869230/reactions
2021-03-11T16:34:07Z
https://api.github.com/repos/huggingface/datasets/issues/comments/796869230
https://avatars.githubusercontent.com/u/8515462?v=4
https://api.github.com/users/albertvillanova/events{/privacy}
https://api.github.com/users/albertvillanova/followers
https://api.github.com/users/albertvillanova/following{/other_user}
https://api.github.com/users/albertvillanova/gists{/gist_id}
https://github.com/albertvillanova
albertvillanova
MDQ6VXNlcjg1MTU0NjI=
https://api.github.com/users/albertvillanova/orgs
https://api.github.com/users/albertvillanova/received_events
https://api.github.com/users/albertvillanova/repos
https://api.github.com/users/albertvillanova/starred{/owner}{/repo}
https://api.github.com/users/albertvillanova/subscriptions
User
https://api.github.com/users/albertvillanova
public
MEMBER
Yes I we should do the same for tensorflow as well since tf models would have the same issue

Thanks for adding this :)
2021-03-11T18:31:43Z
https://github.com/huggingface/datasets/pull/1985#issuecomment-796951164
https://api.github.com/repos/huggingface/datasets/issues/1985
MDEyOklzc3VlQ29tbWVudDc5Njk1MTE2NA==
https://api.github.com/repos/huggingface/datasets/issues/comments/796951164/reactions
2021-03-11T18:31:43Z
https://api.github.com/repos/huggingface/datasets/issues/comments/796951164
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
MEMBER
@lhoestq I think this PR is ready... :)
2021-03-16T08:43:20Z
https://github.com/huggingface/datasets/pull/1985#issuecomment-800069682
https://api.github.com/repos/huggingface/datasets/issues/1985
MDEyOklzc3VlQ29tbWVudDgwMDA2OTY4Mg==
https://api.github.com/repos/huggingface/datasets/issues/comments/800069682/reactions
2021-03-16T08:43:20Z
https://api.github.com/repos/huggingface/datasets/issues/comments/800069682
https://avatars.githubusercontent.com/u/8515462?v=4
https://api.github.com/users/albertvillanova/events{/privacy}
https://api.github.com/users/albertvillanova/followers
https://api.github.com/users/albertvillanova/following{/other_user}
https://api.github.com/users/albertvillanova/gists{/gist_id}
https://github.com/albertvillanova
albertvillanova
MDQ6VXNlcjg1MTU0NjI=
https://api.github.com/users/albertvillanova/orgs
https://api.github.com/users/albertvillanova/received_events
https://api.github.com/users/albertvillanova/repos
https://api.github.com/users/albertvillanova/starred{/owner}{/repo}
https://api.github.com/users/albertvillanova/subscriptions
User
https://api.github.com/users/albertvillanova
public
Optimize int precision to reduce dataset file size.

Close #1973, close #1825, close #861.