Skip to content

Commit d7975e7

Browse files
zhangyubo0722TingquanGao
authored andcommitted
ix gpu memory growth
1 parent 3b15f91 commit d7975e7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

paddleseg/core/train.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16+
import gc
1617
import time
1718
import yaml
1819
import json
@@ -367,13 +368,15 @@ def train(model,
367368
os.path.join(current_save_dir, 'model.pdopt'))
368369
if uniform_output_enabled:
369370
export(cli_args, model, current_save_dir)
371+
gc.collect()
370372

371373
if use_ema:
372374
paddle.save(
373375
ema_model.state_dict(),
374376
os.path.join(current_save_dir, 'ema_model.pdparams'))
375377
if uniform_output_enabled:
376378
export(cli_args, ema_model, current_save_dir, use_ema)
379+
gc.collect()
377380

378381
save_models.append(current_save_dir)
379382
if len(save_models) > keep_checkpoint_max > 0:
@@ -405,6 +408,7 @@ def train(model,
405408
os.path.join(best_model_dir, 'model.pdstates'))
406409
if uniform_output_enabled:
407410
export(cli_args, model, best_model_dir)
411+
gc.collect()
408412
save_model_info(states_dict, best_model_dir)
409413
update_train_results(cli_args,
410414
"best_model",
@@ -450,6 +454,7 @@ def train(model,
450454
if uniform_output_enabled:
451455
export(cli_args, ema_model, best_ema_model_dir,
452456
use_ema)
457+
gc.collect()
453458
save_model_info(ema_states_dict,
454459
best_ema_model_dir)
455460
update_train_results(cli_args,

0 commit comments

Comments
 (0)