MCPcopy Create free account
hub / github.com/AnswerDotAI/ModernBERT / compare_structures

Function compare_structures

tests/test_sequence_packer.py:64–77  ·  view source on GitHub ↗
(s1, s2, rtol=1e-5, atol=1e-8)

Source from the content-addressed store, hash-verified

62
63
64def compare_structures(s1, s2, rtol=1e-5, atol=1e-8):
65 if type(s1) != type(s2):
66 return False
67 if isinstance(s1, dict):
68 if set(s1.keys()) != set(s2.keys()):
69 return False
70 return all(compare_structures(s1[k], s2[k], rtol, atol) for k in s1.keys())
71 if isinstance(s1, list):
72 if len(s1) != len(s2):
73 return False
74 return all(compare_structures(i1, i2, rtol, atol) for i1, i2 in zip(s1, s2))
75 if isinstance(s1, torch.Tensor):
76 return torch.allclose(s1, s2, rtol=rtol, atol=atol)
77 return s1 == s2
78
79
80def test_packer():

Calls

no outgoing calls

Tested by

no test coverage detected