check if eigenvalues of covariance matrix are complex. (#34037)

check if eigenvalues of covariance complex for psd checking
This commit is contained in:
Mohamed Abu El-Nasr
2024-10-10 15:44:05 +03:00
committed by GitHub
parent fb0c6b521d
commit 4a3f1a686f
2 changed files with 2 additions and 5 deletions

View File

@@ -2441,8 +2441,9 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
covariance = old_centered_embeddings.T @ old_centered_embeddings / old_num_tokens
# Check if the covariance is positive definite.
eigenvalues = torch.linalg.eigvals(covariance)
is_covariance_psd = bool(
(covariance == covariance.T).all() and (torch.linalg.eigvals(covariance).real >= 0).all()
(covariance == covariance.T).all() and not torch.is_complex(eigenvalues) and (eigenvalues > 0).all()
)
if is_covariance_psd:
# If covariances is positive definite, a distribution can be created. and we can sample new weights from it.

View File

@@ -694,10 +694,6 @@ class ReformerLocalAttnModelTest(ReformerTesterMixin, GenerationTesterMixin, Mod
self.model_tester.seq_length = original_sequence_length
return test_inputs
@unittest.skip(reason="Resizing sometimes goes bad") # not worth investigating for now (it's not a popular model)
def test_resize_tokens_embeddings(self):
pass
@require_torch
class ReformerLSHAttnModelTest(