Skip to content

Conversation

@ScoThunder
Copy link
Contributor

@ScoThunder ScoThunder commented Jul 19, 2023

日志:root@p-kunlunxin-r480-005:/data/dufeilei/dev/code/FlagPerf/training/benchmarks/bert/pytorch/log/train_1x8.log
数据集:root@p-kunlunxin-r480-005:/data/datasets_ckpt/bert/train

dist_pytorch.barrier(config.vendor)
if config.vendor == 'kunlunxin':
import torch_xmlir.core.xpu_model as xm
xm.mark_step()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前跑图模式需要这个xm.mark_step,现在是eager模式,不需要了

from apex.parallel import DistributedDataParallel as APEX_DDP
from apex.parallel.distributed import flat_dist_call
except ImportError:
print("import apex error")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kunlunxin的机器没有apex,import会报错,加入try catch

import utils
import config
#from converter import convert_model
from .distributed_fused_lamb import _pipeline_block_reductions_patched, _pipeline_step_patched
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

from torch.nn.parallel import DistributedDataParallel as DDP
from torch.optim import Optimizer
from torch_xmlir.optimizer import Lamb
from torch_xmlir.optimizer import FusedLAMB
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

替换为fuse优化器

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请提供kulunxin机器上跑通的截图

# e5m2_allgather=config.dwu_e5m2_allgather)
#optimizer.set_global_scale(float(os.getenv("INIT_LOSS_SCALE", 2 ** 20)))
else:
optimizer = Lamb(optimizer_grouped_parameters,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除多余代码

use_ddp = dist.is_initialized()
if use_ddp and config.use_xpu:
from torch_xmlir.distributed import DistributedDataParallel as DDP
model = DDP(model)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

替换为torch原生的ddp,而不是自定的ddp

optimizer,
delay_overflow_check=self.config.
allreduce_post_accumulation) as scaled_loss:
scaled_loss.backward()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除冗余代码

if update_step:
update_model_params(loss, optimizer, grad_scaler)
else:
xm.mark_step()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eager模式不用xm.mark_step

param.grad = None
else:
xm.optimizer_step(optimizer, barrier=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除多余代码

@yuzhou03 yuzhou03 merged commit ddacd61 into flagos-ai:main Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants