Skip to content

使用colossalai原生的fp16是否会导致clip_grad_norm无效? #2252

Answered by 1SAA
yhcc asked this question in Community | Q&A
Discussion options

You must be logged in to vote

@yhcc

直接使用NaiveAMPOptimizer的clip_grad_norm函数是不正确的行为。如果要使用grad_clipping功能,需要在amp_config中特别标出。如下面这部分展示的代码:

    naive_amp_config = dict(initial_scale=128, clip_grad_norm=1.0)
    naive_amp_model, naive_amp_optimizer = convert_to_naive_amp(naive_amp_model, naive_amp_optimizer, naive_amp_config)

在之后的代码中并不需要调用clip_grad_norm函数,FP16Optimizer会自己在step()函数中调用。

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yhcc
Comment options

Answer selected by yhcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants