-
Notifications
You must be signed in to change notification settings - Fork 505
Migrating training scripts to torchrun #1933
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1933 +/- ##
==========================================
- Coverage 96.80% 96.74% -0.06%
==========================================
Files 172 172
Lines 8442 8442
==========================================
- Hits 8172 8167 -5
- Misses 270 275 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
Mh Normally in this case I think we can merge both scripts into one (DDP & the normal train script) ? - because the logic is the same - anyway what we should test is that the logging does still work with torchrun (W&B for example)
if args.backend:
torch.cuda.set_device(rank)
dist.init_process_group(backend=args.backend)
@@ -185,65 +192,105 @@ def evaluate(model, val_loader, batch_transforms, val_metric, amp=False, log=Non | |||
|
|||
|
|||
def main(args): | |||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove docstring please
world_size (int): number of processes participating in the job | ||
args: other arguments passed through the CLI | ||
""" | ||
world_size = int(os.environ.get("WORLD_SIZE", 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add the same comment here as you did in the recognition script :)
x, target = next(iter(train_loader)) | ||
plot_samples(x, target) | ||
return | ||
# return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the return please 👍
parser.add_argument( | ||
"--save-interval-epoch", dest="save_interval_epoch", action="store_true", help="Save model every epoch" | ||
) | ||
parser.add_argument("--input_size", type=int, default=1024, help="model input size, H = W") | ||
parser.add_argument("--lr", type=float, default=0.001, help="learning rate for the optimizer (Adam or AdamW)") | ||
parser.add_argument("--wd", "--weight-decay", default=0, type=float, help="weight decay", dest="weight_decay") | ||
parser.add_argument("-j", "--workers", type=int, default=None, help="number of workers used for dataloading") | ||
parser.add_argument("-j", "--workers", type=int, default=0, help="number of workers used for dataloading") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep None
here as we did in the recognition script :)
|
||
class_names = val_set.class_names | ||
else: | ||
class_names = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh I think the class_names needs to be shared so no else
-> class_names=val_set.class_names,
torch.save(params.state_dict(), Path(args.output_dir) / f"{exp_name}.pt") | ||
min_loss = val_loss | ||
if args.save_interval_epoch: | ||
pbar.write(f"Saving state at epoch: {epoch + 1}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for interval saving also:
params = model.module if hasattr(model, "module") else model
torch.save(params.state_dict(), Path(args.output_dir) / f"{exp_name}_epoch{epoch + 1}.pt")
No description provided.