Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added graphics card check to prevent cards < ampere errors on bfloat1… #2

Merged
merged 2 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
webdataset
transformers
warmup_scheduler
pytorch-tools @ git+https://github.com/pabloppp/pytorch-tools@master
12 changes: 8 additions & 4 deletions train_stage_B.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from modules import Paella, sample, EfficientNetEncoder, Wrapper
from utils import WebdatasetFilter, transforms, effnet_preprocess, identity
import transformers
from transformers.utils import is_torch_bf16_available, is_torch_tf32_available
transformers.utils.logging.set_verbosity_error()

# PARAMETERS
Expand Down Expand Up @@ -65,8 +66,11 @@ def train(gpu_id, world_size, n_nodes):
ddp_setup(gpu_id, world_size, n_nodes, node_id) # <--- DDP
device = torch.device(gpu_id)

torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.allow_tf32 = True
# only ampere gpu architecture allows these
_float16_dtype = torch.float16 if not is_torch_bf16_available() else torch.bfloat16
if is_torch_tf32_available():
torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.allow_tf32 = True

# --- PREPARE DATASET ---
dataset = wds.WebDataset(
Expand Down Expand Up @@ -170,7 +174,7 @@ def train(gpu_id, world_size, n_nodes):
images, captions = next(dataloader_iterator)
images = images.to(device)

with torch.cuda.amp.autocast(dtype=torch.bfloat16), torch.no_grad():
with torch.cuda.amp.autocast(dtype=_float16_dtype), torch.no_grad():
if np.random.rand() < 0.05: # 90% of the time, drop the CLIP text embeddings (indepentently)
clip_captions = [''] * len(captions) # 5% of the time drop all the captions
else:
Expand All @@ -186,7 +190,7 @@ def train(gpu_id, world_size, n_nodes):

effnet_preproc = effnet_preprocess(images)

with torch.cuda.amp.autocast(dtype=torch.bfloat16):
with torch.cuda.amp.autocast(dtype=_float16_dtype):
pred = model(noised_latents, t, effnet_preproc, clip_text_embeddings)
loss = criterion(pred, latents)
loss = ((loss * loss_weight).sum(dim=[1, 2]) / loss_weight.sum(dim=[1, 2])).mean()
Expand Down
15 changes: 10 additions & 5 deletions train_stage_C.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from modules import Paella, sample, EfficientNetEncoder, Prior
from utils import WebdatasetFilter, transforms, effnet_preprocess, identity
import transformers
from transformers.utils import is_torch_bf16_available, is_torch_tf32_available


transformers.utils.logging.set_verbosity_error()

Expand Down Expand Up @@ -67,8 +69,11 @@ def train(gpu_id, world_size, n_nodes):
ddp_setup(gpu_id, world_size, n_nodes, node_id) # <--- DDP
device = torch.device(gpu_id)

torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.allow_tf32 = True
# only ampere gpu architecture allows these
_float16_dtype = torch.float16 if not is_torch_bf16_available() else torch.bfloat16
if is_torch_tf32_available():
torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.allow_tf32 = True

# --- PREPARE DATASET ---
dataset = wds.WebDataset(
Expand Down Expand Up @@ -194,7 +199,7 @@ def train(gpu_id, world_size, n_nodes):

with torch.no_grad():
effnet_features = effnet(effnet_preprocess(images))
with torch.cuda.amp.autocast(dtype=torch.bfloat16):
with torch.cuda.amp.autocast(dtype=_float16_dtype):
if np.random.rand() < 0.05: # 90% of the time, drop the CLIP text embeddings (independently)
clip_captions = [''] * len(captions) # 5% of the time drop all the captions
else:
Expand All @@ -205,7 +210,7 @@ def train(gpu_id, world_size, n_nodes):
t = (1 - torch.rand(images.size(0), device=device)).mul(1.08).add(0.001).clamp(0.001, 1.0)
noised_embeddings, noise = diffuzz.diffuse(effnet_features, t)

with torch.cuda.amp.autocast(dtype=torch.bfloat16):
with torch.cuda.amp.autocast(dtype=_float16_dtype):
pred_noise = model(noised_embeddings, t, clip_text_embeddings)
loss = nn.functional.mse_loss(pred_noise, noise, reduction='none').mean(dim=[1, 2, 3])
loss_adjusted = (loss * diffuzz.p2_weight(t)).mean() / grad_accum_steps
Expand Down Expand Up @@ -299,7 +304,7 @@ def train(gpu_id, world_size, n_nodes):
effnet_embeddings_uncond = torch.zeros_like(effnet_features)
noised_embeddings, noise = diffuzz.diffuse(effnet_features, t)

with torch.cuda.amp.autocast(dtype=torch.bfloat16):
with torch.cuda.amp.autocast(dtype=_float16_dtype):
pred_noise = model(noised_embeddings, t, clip_text_embeddings)
pred = diffuzz.undiffuse(noised_embeddings, t, torch.zeros_like(t), pred_noise)
sampled = diffuzz.sample(model.module, {'c': clip_text_embeddings},
Expand Down
20 changes: 11 additions & 9 deletions würstchen-stage-B.ipynb

Large diffs are not rendered by default.

107 changes: 56 additions & 51 deletions würstchen-stage-C.ipynb

Large diffs are not rendered by default.