check if eigenvalues of covariance matrix are complex. (#34037)
check if eigenvalues of covariance complex for psd checking
This commit is contained in:
committed by
GitHub
parent
fb0c6b521d
commit
4a3f1a686f
@@ -2441,8 +2441,9 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
|
|||||||
covariance = old_centered_embeddings.T @ old_centered_embeddings / old_num_tokens
|
covariance = old_centered_embeddings.T @ old_centered_embeddings / old_num_tokens
|
||||||
|
|
||||||
# Check if the covariance is positive definite.
|
# Check if the covariance is positive definite.
|
||||||
|
eigenvalues = torch.linalg.eigvals(covariance)
|
||||||
is_covariance_psd = bool(
|
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 is_covariance_psd:
|
||||||
# If covariances is positive definite, a distribution can be created. and we can sample new weights from it.
|
# If covariances is positive definite, a distribution can be created. and we can sample new weights from it.
|
||||||
|
|||||||
@@ -694,10 +694,6 @@ class ReformerLocalAttnModelTest(ReformerTesterMixin, GenerationTesterMixin, Mod
|
|||||||
self.model_tester.seq_length = original_sequence_length
|
self.model_tester.seq_length = original_sequence_length
|
||||||
return test_inputs
|
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
|
@require_torch
|
||||||
class ReformerLSHAttnModelTest(
|
class ReformerLSHAttnModelTest(
|
||||||
|
|||||||
Reference in New Issue
Block a user