# FSDP2 Benchmarks This benchmark showcases `FSDP2` in 🤗 `accelerate` and compares it to `torch` baseline. ## Overview This benchmark consists of two parts: - `main.py` is the main script that runs the benchmark - `visualize.py` is the script that visualizes the results (if `--output_dir` was specified for the previous command) ## Motivation We want to showcase that 🤗 `accelerate`'s integration of `FSDP2` is on par raw PyTorch, and highlight a "broken" part in PyTorch that creating an optimizer before applying `FSDP2` **doesn't result in a working training loop**. (more on this later) This script showcases **matching memory usage and convergence between `accelerate` and `torch`'s baseline.** To deal with this breaking change (and maintain backward compatibility with FSDP1 in terms of an API), `accelerate` had to come up with a workaround since `accelerate` assumes that the user will nearly always create a model, optimizer, scheduler, etc beforehand and bring them themselves. This lead to an issue of a stark increase in memory as well as the model not even training if the user creates an optimizer beforehand. To workaround this, we replace the parameters inside the optimizer with the newly created FSDP2 sharded ones. More about this can be found in this [blog post (TBD)](TODO) > [!WARNING] > This script is intended to fit on 2x 24GB GPUs, though on so few GPUs it's not possible to see the memory difference (discrepancies in grad allocation result in lower memory usage in the non-fixed case), only the difference in convergence. Below are attached results from 8x H100 GPUs where the difference is visible. > TLDR: more GPUs = bigger memory difference between fixed and non-fixed cases. ## Results Here are the results from running the benchmark on 8x H100 GPUs: