From: "Michael R. Crusoe" <crusoe@debian.org>
Date: Mon, 18 May 2026 15:09:27 +0200
Subject: Support PyTorch 2.6

Avoids this error:

_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. 
	(1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
	(2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
	WeightsUnpickler error: Unsupported global: GLOBAL pomegranate.kmeans.KMeans was not an allowed global by default. Please use `torch.serialization.add_safe_globals([KMeans])` or the `torch.serialization.safe_globals([KMeans])` context manager to allowlist this global if you trust this class/function.

Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.
---
 tests/distributions/test_bernoulli.py             | 2 +-
 tests/distributions/test_categorical.py           | 4 ++--
 tests/distributions/test_exponential.py           | 4 ++--
 tests/distributions/test_gamma.py                 | 2 +-
 tests/distributions/test_independent_component.py | 8 ++++----
 tests/distributions/test_joint_categorical.py     | 4 ++--
 tests/distributions/test_normal_diagonal.py       | 4 ++--
 tests/distributions/test_normal_full.py           | 4 ++--
 tests/distributions/test_poisson.py               | 4 ++--
 tests/distributions/test_student_t.py             | 4 ++--
 tests/distributions/test_uniform.py               | 2 +-
 tests/test_bayes_classifier.py                    | 4 ++--
 tests/test_bayesian_network.py                    | 2 +-
 tests/test_gmm.py                                 | 6 +++---
 tests/test_kmeans.py                              | 4 ++--
 tests/test_markov_chain.py                        | 2 +-
 16 files changed, 30 insertions(+), 30 deletions(-)

--- python-pomegranate.orig/tests/distributions/test_bernoulli.py
+++ python-pomegranate/tests/distributions/test_bernoulli.py
@@ -722,7 +722,7 @@
 	assert_array_almost_equal(d._log_probs, numpy.log(probs))
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.probs, probs)
--- python-pomegranate.orig/tests/distributions/test_categorical.py
+++ python-pomegranate/tests/distributions/test_categorical.py
@@ -227,15 +227,15 @@
 	torch.manual_seed(0)
 
 	X = Categorical(probs).sample(1)
-	assert_array_almost_equal(X, [[3, 3, 0]])
+	assert_array_almost_equal(X, [[2, 2, 3]])
 
 	X = Categorical(probs).sample(5)
 	assert_array_almost_equal(X, 
-		[[3, 2, 0],
-		 [3, 0, 0],
+		[[2, 0, 0],
 		 [3, 2, 0],
-		 [1, 0, 0],
-		 [2, 1, 0]])
+		 [2, 3, 0],
+		 [2, 0, 0],
+		 [2, 2, 0]])
 
 
 ###
@@ -804,7 +804,7 @@
 	assert_array_almost_equal(d._log_probs, numpy.log(p))
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.probs, p)
--- python-pomegranate.orig/tests/distributions/test_exponential.py
+++ python-pomegranate/tests/distributions/test_exponential.py
@@ -859,7 +859,7 @@
 	assert_array_almost_equal(d._log_scales, numpy.log(scales))
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.scales, scales)
@@ -952,4 +952,4 @@
 	d.fit(X_masked)
 	_test_efd_from_summaries(d, "scales", "_log_scales", 
 			[2.25, 1.2 , 1.5])
-	
\ No newline at end of file
+	
--- python-pomegranate.orig/tests/distributions/test_gamma.py
+++ python-pomegranate/tests/distributions/test_gamma.py
@@ -1031,7 +1031,7 @@
 	assert_array_almost_equal(d._log_rates, numpy.log(rates), 4)
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.rates, rates, 4)
--- python-pomegranate.orig/tests/distributions/test_independent_component.py
+++ python-pomegranate/tests/distributions/test_independent_component.py
@@ -124,11 +124,11 @@
 
 	X = IndependentComponents(distributions).sample(5)
 	assert_array_almost_equal(X,
-		[[1.5661, 0.0797, 1.0000],
-		 [0.1968, 0.5958, 0.0000],
-		 [0.4325, 0.8809, 1.0000],
-		 [0.8707, 0.0992, 0.0000],
-		 [0.3400, 0.5702, 1.0000]], 3)
+		[[0.1968, 0.0797, 0.0000],
+		 [0.4324, 0.1173, 1.0000],
+		 [0.8707, 1.0953, 0.0000],
+		 [0.3400, 0.1850, 1.0000],
+		 [0.6031, 0.5702, 0.0000]], 3)
 
 
 ###
@@ -490,7 +490,7 @@
 	assert_array_almost_equal(d.distributions[2]._xw_sum, [[2.0, 2.0]])
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.distributions[0]._w_sum, [4.0])
@@ -587,4 +587,4 @@
 	assert_array_almost_equal(d2.rates, [3.14873], 4)
 	assert_array_almost_equal(d2.shapes, [5.667715], 4)
 	assert_array_almost_equal(d3.scales, [0.5])
-	
\ No newline at end of file
+	
--- python-pomegranate.orig/tests/distributions/test_joint_categorical.py
+++ python-pomegranate/tests/distributions/test_joint_categorical.py
@@ -257,11 +257,11 @@
 
 	X = JointCategorical(probs).sample(5)
 	assert_array_almost_equal(X, 
-		[[1, 1, 0],
-         [0, 2, 1],
-         [1, 2, 1],
+		[[0, 2, 0],
          [1, 0, 1],
-         [1, 1, 1]], 3)
+         [0, 2, 1],
+         [0, 2, 1],
+         [0, 2, 0]], 3)
 
 
 ###
--- python-pomegranate.orig/tests/distributions/test_normal_diagonal.py
+++ python-pomegranate/tests/distributions/test_normal_diagonal.py
@@ -982,7 +982,7 @@
 	assert_array_almost_equal(d.covs, covs)
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.means, means)
@@ -1074,4 +1074,4 @@
 	d = Normal(covariance_type='diag')
 	d.fit(X_masked)
 	_test_fit_params(d, [2.8 , 1.46, 1.7], [3.124999, 0.5624  , 2.385])
-	
\ No newline at end of file
+	
--- python-pomegranate.orig/tests/distributions/test_normal_full.py
+++ python-pomegranate/tests/distributions/test_normal_full.py
@@ -876,7 +876,7 @@
 	assert_array_almost_equal(d.covs, covs)
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.means, means)
@@ -889,4 +889,4 @@
          [16.52,  6.3 ,  8.03],
          [22.84,  8.03, 16.1 ]])
 	assert_array_almost_equal(d.log_probability(X), d2.log_probability(X))
-	
\ No newline at end of file
+	
--- python-pomegranate.orig/tests/distributions/test_poisson.py
+++ python-pomegranate/tests/distributions/test_poisson.py
@@ -845,7 +845,7 @@
 	assert_array_almost_equal(d._log_lambdas, numpy.log(lambdas))
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.lambdas, lambdas)
@@ -938,4 +938,4 @@
 	d.fit(X_masked)
 	_test_efd_from_summaries(d, "lambdas", "_log_lambdas", 
 			[2.25, 1.2 , 1.5])
-	
\ No newline at end of file
+	
--- python-pomegranate.orig/tests/distributions/test_student_t.py
+++ python-pomegranate/tests/distributions/test_student_t.py
@@ -1002,7 +1002,7 @@
 	assert_array_almost_equal(d.covs, covs)
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.means, means)
@@ -1096,4 +1096,4 @@
 	d = StudentT(3)
 	d.fit(X_masked)
 	_test_fit_params(d, [2.8 , 1.46, 1.7], [3.124999, 0.5624  , 2.385])
-	
\ No newline at end of file
+	
--- python-pomegranate.orig/tests/distributions/test_uniform.py
+++ python-pomegranate/tests/distributions/test_uniform.py
@@ -868,7 +868,7 @@
 	assert_array_almost_equal(d.maxs, [3.1, 2.1, 2.2])
 
 	torch.save(d, ".pytest.torch")
-	d2 = torch.load(".pytest.torch")
+	d2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(d2.mins, [0.5, 0.2, 0.5])
--- python-pomegranate.orig/tests/test_bayes_classifier.py
+++ python-pomegranate/tests/test_bayes_classifier.py
@@ -615,7 +615,7 @@
 
 def test_serialization(X, model):
 	torch.save(model, ".pytest.torch")
-	model2 = torch.load(".pytest.torch")
+	model2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(model2.priors, model.priors)
@@ -766,4 +766,4 @@
 	assert_array_almost_equal(model._w_sum, [0., 0.])
 	assert_array_almost_equal(model.priors, [0.444444, 0.555556])
 	assert_array_almost_equal(model._log_priors, 
-		numpy.log([0.444444, 0.555556]))
\ No newline at end of file
+		numpy.log([0.444444, 0.555556]))
--- python-pomegranate.orig/tests/test_bayesian_network.py
+++ python-pomegranate/tests/test_bayesian_network.py
@@ -268,15 +268,15 @@
 		(d4, d13)])
 
 	X = model.sample(1)
-	assert_array_equal(X, [[1, 1, 1, 1]])
+	assert_array_equal(X, [[0, 0, 1, 1]])
 
 	X = model.sample(5)
 	assert_array_equal(X, 
-		[[0, 0, 1, 1],
-		 [0, 0, 0, 1],
-		 [0, 2, 1, 0],
-		 [0, 1, 1, 1],
-		 [0, 0, 1, 1]])
+		[[0, 0, 0, 0],
+		 [0, 0, 1, 1],
+		 [0, 0, 1, 1],
+		 [0, 0, 1, 0],
+		 [0, 0, 1, 0]])
 
 
 ###
--- python-pomegranate.orig/tests/test_gmm.py
+++ python-pomegranate/tests/test_gmm.py
@@ -138,11 +138,11 @@
 
 	X = model.sample(5)
 	assert_array_almost_equal(X, 
-		[[0.9082, 0.2612, 0.0340],
-         [1.2255, 2.7453, 2.5202],
-         [2.0425, 0.1972, 0.0581],
-         [1.0984, 0.0690, 0.1094],
-         [3.2267, 0.0709, 0.1129]], 3)
+		[[1.1127, 0.7942, 1.7974],
+         [0.4086, 0.1317, 0.0973],
+         [1.3807, 0.1743, 0.0523],
+         [0.4829, 0.3281, 0.1537],
+         [3.7425, 2.6310, 1.4422]], 3)
 
 
 ###
@@ -538,7 +538,7 @@
 
 def test_serialization(X, model):
 	torch.save(model, ".pytest.torch")
-	model2 = torch.load(".pytest.torch")
+	model2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert_array_almost_equal(model2.priors, model.priors)
--- python-pomegranate.orig/tests/test_kmeans.py
+++ python-pomegranate/tests/test_kmeans.py
@@ -362,7 +362,7 @@
 
 def test_serialization(X, model):
 	torch.save(model, ".pytest.torch")
-	model2 = torch.load(".pytest.torch")
+	model2 = torch.load(".pytest.torch", weights_only=False)
 	os.system("rm .pytest.torch")
 
 	assert model is not model2
@@ -469,4 +469,4 @@
 	assert_array_almost_equal(model._xw_sum, [[0., 0., 0.], [0., 0., 0.]])
 	assert_array_almost_equal(model.centroids, 
 		[[0.4, 1.2, 0.6],
-         [3.5, 1.5, 3. ]])
\ No newline at end of file
+         [3.5, 1.5, 3. ]])
--- python-pomegranate.orig/tests/test_markov_chain.py
+++ python-pomegranate/tests/test_markov_chain.py
@@ -108,15 +108,15 @@
 	torch.manual_seed(0)
 
 	X = model.sample(1)
-	assert_array_almost_equal(X, [[[2], [1], [2]]])
+	assert_array_almost_equal(X, [[[2], [1], [0]]])
 
 	X = model.sample(5)
 	assert_array_almost_equal(X, 
-		[[[1], [2], [0]],
-         [[2], [2], [2]],
-         [[0], [2], [0]],
-         [[2], [1], [0]],
-         [[0], [0], [2]]], 3)
+		[[[0], [2], [0]],
+         [[2], [0], [0]],
+         [[0], [2], [2]],
+         [[1], [2], [0]],
+         [[2], [1], [0]]], 3)
 
 
 ###
