def compare_optimizer(opt1, opt2, shape, dtype, w_stype='<STR_LIT:default>', g_stype='<STR_LIT:default>',<EOL>rtol=<NUM_LIT>, atol=<NUM_LIT>, compare_states=True):
if w_stype == '<STR_LIT:default>':<EOL><INDENT>w2 = mx.random.uniform(shape=shape, ctx=default_context(), dtype=dtype)<EOL>w1 = w2.copyto(default_context())<EOL><DEDENT>elif w_stype == '<STR_LIT>' or w_stype == '<STR_LIT>':<EOL><INDENT>w2 = rand_ndarray(shape, w_stype, density=<NUM_LIT:1>, dtype=dtype)<EOL>w1 = w2.copyto(default_context()).tostype('<STR_LIT:default>')<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>if g_stype == '<STR_LIT:default>':<EOL><INDENT>g2 = mx.random.uniform(shape=shape, ctx=default_context(), dtype=dtype)<EOL>g1 = g2.copyto(default_context())<EOL><DEDENT>elif g_stype == '<STR_LIT>' or g_stype == '<STR_LIT>':<EOL><INDENT>g2 = rand_ndarray(shape, g_stype, dtype=dtype)<EOL>g1 = g2.copyto(default_context()).tostype('<STR_LIT:default>')<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>state1 = opt1.create_state_multi_precision(<NUM_LIT:0>, w1)<EOL>state2 = opt2.create_state_multi_precision(<NUM_LIT:0>, w2)<EOL>if compare_states:<EOL><INDENT>compare_ndarray_tuple(state1, state2)<EOL><DEDENT>opt1.update_multi_precision(<NUM_LIT:0>, w1, g1, state1)<EOL>opt2.update_multi_precision(<NUM_LIT:0>, w2, g2, state2)<EOL>if compare_states:<EOL><INDENT>compare_ndarray_tuple(state1, state2, rtol=rtol, atol=atol)<EOL><DEDENT>assert_almost_equal(w1.asnumpy(), w2.asnumpy(), rtol=rtol, atol=atol)<EOL>
Compare opt1 and opt2.