Is it possible that Accelerate may not divide the data evenly among processes?
I’m currently using HuggingFace Accelerate to train a model and usingsklearn.metrics.classification_reportto get the results. I noticed that the support values for certain classes differ depending on whether I’m using one process vs. multiple processes.I asked ChatGPT (lol) whether this may be true and it turns out that if the data is unevenly distributed then this may be a problem. I’m wondering how true this is because my initial intuition was that even if there’s an uneven distribution the data should still be divided (even if not perfectly equally) and later gathered, therefore the support shouldn’t differ.Please let me know if I’m thinking incorrectly. Thanks.
2023-07-04T15:43:46Z
seanswyi:Please let me know if I’m thinking incorrectly. Thanks.Are you gathering? Please see the example script on metrics:https://github.com/huggingface/accelerate/blob/main/examples/nlp_example.py#L180-L184
2023-07-05T00:39:11Z
I’m actually not gathering as your suggested example. The way that my code is structured is that I refactored an existing project slightly so that I can use HF Accelerate without refactoring thingstoomuch.The way that the code is currently gathering is by usingtorch.distributed.all_gather_object. More specifically, I have an intermediate value that contains predictions and labels inside of the evaluation loop, then after inference I gather everything into a final array-like object in order to perform evaluation using scikit-learn:import torch.distributed as dist

intermediate_value = {}
output = [None] * accelerator.num_processes
for step, batch in enumerate(valid_dataloader):
    y_pred = model(batch)
    intermediate_value.setdefault("preds", []).append(y_pred)
    intermediate_value.setdefault("targets", []).append(batch["target"])

dist.all_gather_object(output, intermediate_value)Is this approach not suggested? I would assume that this approach should work just fine but I’m wondering if there would be a difference between using HF’s approach.
2023-07-05T02:17:19Z
seanswyi:Is this approach not suggested? I would assume that this approach should work just fine but I’m wondering if there would be a difference between using HF’s approach.You’re going to have extra items in here, so as always please definitely use the API otherwise you’ll need to drop the repeats etc