# Multigpu precompute dataset map function and share between processes

**URL:** <https://discuss.huggingface.co/t/multigpu-precompute-dataset-map-function-and-share-between-processes/96143>\
**Category:** 🤗Accelerate\
**Created:** [July 8, 2024, 11:54am UTC](https://discuss.huggingface.co/t/multigpu-precompute-dataset-map-function-and-share-between-processes/96143 "2024-07-08T11:54:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DealayLomoi](https://avatars.discourse-cdn.com/v4/letter/d/7cd45c/32.png) [@DealayLomoi](https://discuss.huggingface.co/u/DealayLomoi)\
**Post date:** [July 8, 2024, 11:54am UTC](https://discuss.huggingface.co/t/multigpu-precompute-dataset-map-function-and-share-between-processes/96143/1 "2024-07-08T11:54:19Z")

</div>

Here’ codes that precompute data using `main_process_first()` which use 1st gpu to caculate all precomputation and shares results across all processes. However, using one gpu to precompute on big data is slow, can we use all gpu multi-processing-ly and finally merge data in one piece which shares across all processes.

> <https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_sdxl.py>

```auto
 with accelerator.main_process_first():
        from datasets.fingerprint import Hasher

        # fingerprint used by the cache for the other processes to load the result
        # details: https://github.com/huggingface/diffusers/pull/4038#discussion_r1266078401
        new_fingerprint = Hasher.hash(args)
        new_fingerprint_for_vae = Hasher.hash(vae_path)
        train_dataset_with_embeddings = train_dataset.map(
            compute_embeddings_fn, batched=True, new_fingerprint=new_fingerprint

```
