@@ -100,11 +100,11 @@ def test_block_ops(self):
100100
101101 shape = (self .batch_size , self .seq_len , self .bonsai_config .d_model )
102102 jx = jax .random .normal (jax .random .key (0 ), shape , jnp .float32 )
103- tx = torch .tensor (jx )
103+ tx = torch .tensor (np . asarray ( jx ) )
104104
105105 for attr in ["q_proj" , "k_proj" , "v_proj" , "ff_proj" , "up_proj" ]:
106106 ty , ny = getattr (tm , attr )(tx ), getattr (nm , attr )(jx , out_sharding = None )
107- np .testing .assert_allclose (ny , ty .detach ().cpu ().numpy (), err_msg = attr )
107+ np .testing .assert_allclose (ny , ty .detach ().cpu ().numpy (), atol = 5e-6 , err_msg = attr )
108108
109109 # norms
110110 for attr in ["attn_norm" , "ff_norm" ]:
@@ -114,10 +114,10 @@ def test_block_ops(self):
114114 # ff_out
115115 shape = (self .batch_size , self .seq_len , self .bonsai_config .mlp_hidden_size )
116116 jx = jax .random .normal (jax .random .key (0 ), shape , jnp .float32 )
117- tx = torch .tensor (jx )
117+ tx = torch .tensor (np . asarray ( jx ) )
118118
119119 ty , ny = tm .ff_out (tx ), nm .ff_out (jx , out_sharding = None )
120- np .testing .assert_allclose (ny , ty .detach ().cpu ().numpy (), err_msg = "ff_out" )
120+ np .testing .assert_allclose (ny , ty .detach ().cpu ().numpy (), atol = 5e-6 , err_msg = "ff_out" )
121121
122122 def test_wte (self ):
123123 tm = self .baseline_model .model .transformer ["wte" ]
@@ -135,7 +135,7 @@ def test_rmsnorm(self):
135135
136136 shape = (self .batch_size , self .seq_len , self .bonsai_config .d_model )
137137 jx = jax .random .normal (jax .random .key (0 ), shape , jnp .float32 )
138- tx = torch .tensor (jx )
138+ tx = torch .tensor (np . asarray ( jx ) )
139139
140140 ty , ny = tm (tx ), nm (jx )
141141 np .testing .assert_allclose (ny , ty .detach ().cpu ().numpy (), rtol = 5e-7 , atol = 5e-7 )
@@ -146,7 +146,7 @@ def test_ff_out(self):
146146
147147 shape = (self .batch_size , self .seq_len , self .bonsai_config .d_model )
148148 jx = jax .random .normal (jax .random .key (0 ), shape , jnp .float32 )
149- tx = torch .tensor (jx )
149+ tx = torch .tensor (np . asarray ( jx ) )
150150
151151 ty , ny = tm (tx ), nm (jx , out_sharding = None )
152152 np .testing .assert_allclose (ny , ty .detach ().cpu ().numpy (), rtol = 2e-6 , atol = 2e-6 )
@@ -176,7 +176,7 @@ def test_block(self):
176176 shape = (self .batch_size , self .seq_len , self .bonsai_config .d_model )
177177 jx = jax .random .normal (jax .random .key (0 ), shape , jnp .float32 )
178178 segment_ids = jnp .ones ((self .batch_size , self .seq_len ), jnp .int32 )
179- tx = torch .tensor (jx )
179+ tx = torch .tensor (np . asarray ( jx ) )
180180
181181 left_pads = modeling .count_left_pads (segment_ids )
182182 start_ind = left_pads .reshape ((- 1 , 1 ))
0 commit comments