Repository navigation
Conversation
fegin
left a comment
There was a problem hiding this comment.
LGTM in general, one comment of the model conversion. I feel next time it is good to have the refactor part as a separate PR from the bug fix PRs.
| assert len(self.model_parts) == 1 | ||
| model = self.model_parts[0] | ||
| # explicitely convert flux model to be Bfloat16 no matter FSDP is applied or not | ||
| model = self.model_parts[0].to(self._dtype) |
There was a problem hiding this comment.
I think we should move this to __init__(), we don't want to do the conversion every iteration if the model is fixed to an certain dtype.
tianyu-l
left a comment
There was a problem hiding this comment.
we need to be a bit careful on the dtype conversion -- I left a comment
| model_parts = self.model_parts | ||
| assert len(self.model_parts) == 1 | ||
| model = self.model_parts[0] | ||
| # explicitely convert flux model to be Bfloat16 no matter FSDP is applied or not |
There was a problem hiding this comment.
With FSDP, it is not the same before vs. after this PR.
- before: sharded params are in fp32, reduce-scatter is in fp32, so gradient updates happen in fp32
- after: sharded params are converted to bf16, reduce-scatter is in fp32, I would guess gradient updates happen in fp16 after a dtype conversion
How about we do the following?
explicitly convert dtype of encoder to training.mixed_precision_param if fsdp is used
There was a problem hiding this comment.
Hmm, what's the actual dtype the model is going to use without any parallelisms? If it is bf16, then we should always bf16 even if FSDP is applied.
There was a problem hiding this comment.
With FSDP: Tianyu's plan (before this PR version) is the most accurate version.
- before: sharded params are in fp32, reduce-scatter is in fp32, so gradient updates happen in fp32
- Encoder dtypes: bfloat16
Without any parallelism, I guess the actual / most-accurate dtype should be float32.
…n layer shape issue (pytorch#1153) ## What changed? 1. Refactor Flux arg parser to follow pytorch#767 new argparse practice 2. Explicitly change dtype for flux model to avoid pytorch#1137 (when FSDP is not enabled) 3. Fix txt_in layer shape issue by changing the config of schnell and dev model pytorch#1146 ## dtype management in Flux Training Without FSDP (fsdp dim = 1) : - Encoder's dtype = float32, Flux model's dtype = float32 With FSDP enabled: - Encoder's dtype = bfloat16, Text and Image encodings' dtype=bfloat16 - Flux Model's dtype: sharded params are in fp32, reduce-scatter is in fp32, so gradient updates happen in fp32. dtype when calculation=bfloat16 cc @CarlosGomes98
…n layer shape issue (pytorch#1153) ## What changed? 1. Refactor Flux arg parser to follow pytorch#767 new argparse practice 2. Explicitly change dtype for flux model to avoid pytorch#1137 (when FSDP is not enabled) 3. Fix txt_in layer shape issue by changing the config of schnell and dev model pytorch#1146 ## dtype management in Flux Training Without FSDP (fsdp dim = 1) : - Encoder's dtype = float32, Flux model's dtype = float32 With FSDP enabled: - Encoder's dtype = bfloat16, Text and Image encodings' dtype=bfloat16 - Flux Model's dtype: sharded params are in fp32, reduce-scatter is in fp32, so gradient updates happen in fp32. dtype when calculation=bfloat16 cc @CarlosGomes98
What changed?
dtype management in Flux Training
Without FSDP (fsdp dim = 1) :
With FSDP enabled:
cc @CarlosGomes98