Pre-Processing Cache Fails when using a Factory pattern
NONE
Ok - this is still an issue but I believe the root cause is different than I originally thought. I'm now able to get caching to work consistently with the above example as long as I fix the python hash seed `export PYTHONHASHSEED=1234`
2022-03-02T21:53:48Z
https://github.com/huggingface/datasets/issues/3808#issuecomment-1057429776
https://api.github.com/repos/huggingface/datasets/issues/3808
IC_kwDODunzps4_BxkQ
https://api.github.com/repos/huggingface/datasets/issues/comments/1057429776/reactions
2022-03-02T21:53:48Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1057429776
https://avatars.githubusercontent.com/u/9847335?v=4
https://api.github.com/users/Helw150/events{/privacy}
https://api.github.com/users/Helw150/followers
https://api.github.com/users/Helw150/following{/other_user}
https://api.github.com/users/Helw150/gists{/gist_id}
https://github.com/Helw150
Helw150
MDQ6VXNlcjk4NDczMzU=
https://api.github.com/users/Helw150/orgs
https://api.github.com/users/Helw150/received_events
https://api.github.com/users/Helw150/repos
https://api.github.com/users/Helw150/starred{/owner}{/repo}
https://api.github.com/users/Helw150/subscriptions
User
https://api.github.com/users/Helw150
public
COLLABORATOR
Hi! 

Yes, our hasher should work with decorators. For instance, this dummy example:
```python
def f(arg):
    def f1(ex):
        return {"a": ex["col1"] + arg}
    return f1
```
gives the same hash across different Python sessions (`datasets.fingerprint.Hasher.hash(f("string1")` returns `"408c9059f89dbd6c"` on my machine).

Could you please make the example self-contained? This way, we can reproduce the bug. Additionally, you can try to find the problematic object yourself by testing their hash with `datasets.fingerprint.Hasher.hash(obj)`

This could be related to https://github.com/huggingface/datasets/issues/3638.
2022-03-03T14:28:22Z
https://github.com/huggingface/datasets/issues/3808#issuecomment-1058096948
https://api.github.com/repos/huggingface/datasets/issues/3808
IC_kwDODunzps4_EUc0
https://api.github.com/repos/huggingface/datasets/issues/comments/1058096948/reactions
2022-03-03T14:30:09Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1058096948
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
NONE
#3638 was indeed my issue. Thanks!
2022-03-10T23:01:46Z
https://github.com/huggingface/datasets/issues/3808#issuecomment-1064595059
https://api.github.com/repos/huggingface/datasets/issues/3808
IC_kwDODunzps4_dG5z
https://api.github.com/repos/huggingface/datasets/issues/comments/1064595059/reactions
2022-03-10T23:01:46Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1064595059
https://avatars.githubusercontent.com/u/9847335?v=4
https://api.github.com/users/Helw150/events{/privacy}
https://api.github.com/users/Helw150/followers
https://api.github.com/users/Helw150/following{/other_user}
https://api.github.com/users/Helw150/gists{/gist_id}
https://github.com/Helw150
Helw150
MDQ6VXNlcjk4NDczMzU=
https://api.github.com/users/Helw150/orgs
https://api.github.com/users/Helw150/received_events
https://api.github.com/users/Helw150/repos
https://api.github.com/users/Helw150/starred{/owner}{/repo}
https://api.github.com/users/Helw150/subscriptions
User
https://api.github.com/users/Helw150
public
## Describe the bug
If you utilize a pre-processing function which is created using a factory pattern, the function hash changes on each run (even if the function is identical) and therefore the data will be reproduced each time.

## Steps to reproduce the bug
```python
    def preprocess_function_factory(augmentation=None):
        def preprocess_function(examples):
            # Tokenize the texts
            if augmentation:
                conversions1 = [
                    augmentation(example)
                    for example in examples[sentence1_key]
                ]
                if sentence2_key is None:
                    args = (conversions1,)
                else:
                    conversions2 = [
                        augmentation(example)
                        for example in examples[sentence2_key]
                    ]
                    args = (conversions1, conversions2)
            else:
                args = (
                    (examples[sentence1_key],)
                    if sentence2_key is None
                    else (examples[sentence1_key], examples[sentence2_key])
                )
            result = tokenizer(
                *args, padding=padding, max_length=max_seq_length, truncation=True
            )

            # Map labels to IDs (not necessary for GLUE tasks)
            if label_to_id is not None and "label" in examples:
                result["label"] = [
                    (label_to_id[l] if l != -1 else -1) for l in examples["label"]
                ]
            return result

        return preprocess_function

capitalize = lambda x: x.capitalize()
preprocess_function = preprocess_function_factory(augmentation=capitalize)
print(hash(preprocess_function)) # This will change on each run
raw_datasets = raw_datasets.map(
        preprocess_function,
        batched=True,
        load_from_cache_file=True,
        desc="Running transformation and tokenizer on dataset",
)
```

## Expected results
Running the code twice will cause the cache to be re-used.

## Actual results
Running the code twice causes the whole dataset to be re-processed
