Skip to content

Commit

Permalink
Merge branch 'main' of github.com:loreloc/sos-npcs into main
Browse files Browse the repository at this point in the history
  • Loading branch information
loreloc committed Jul 21, 2024
2 parents 35e4669 + ad62bb2 commit 11ec3fe
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions econfigs/complex-squared-npcs.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"batch-size": 512,
"optimizer": "Adam",
"verbose": true,
"learning-rate": [5e-4, 1e-3, 5e-3, 1e-2],
"learning-rate": [1e-4, 5e-4, 1e-3, 5e-3],
"num-components": 1
},
"models": {
Expand Down Expand Up @@ -59,17 +59,17 @@
},
"miniboone": {
"MPC": {
"num-units": 64,
"num-units": 128,
"num-input-units": 64
},
"SOS": {
"real": {
"num-units": 64,
"num-units": 128,
"num-input-units": 64,
"complex": false
},
"complex": {
"num-units": 32,
"num-units": 64,
"num-input-units": 64,
"complex": true
}
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
git+ssh://git@github.com/april-tools/cirkit.git@complex-circuits
torch~=2.2.0
numpy<2.0.0
pandas<2.0.0
scikit-learn
zuko
Expand Down
6 changes: 5 additions & 1 deletion src/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def __init__(
assert weight1.num_folds == num_folds
assert weight2.num_folds == num_folds
super().__init__(
num_input_units, num_output_units, arity=1, num_folds=num_folds, semiring=semiring
num_input_units,
num_output_units,
arity=1,
num_folds=num_folds,
semiring=semiring,
)
self._in_shape = (weight1.shape[1], weight2.shape[1])
self.weight1 = weight1
Expand Down
21 changes: 9 additions & 12 deletions src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from cirkit.symbolic.parameters import (
ExpParameter,
Parameter,
ClampParameter,
TensorParameter,
TensorParameter, ScaledSigmoidParameter,
)
from cirkit.templates.region_graph import (
RegionGraph,
Expand Down Expand Up @@ -184,7 +183,7 @@ def __init__(
backend="torch", semiring="complex-lse-sum", fold=True, optimize=True
)
# Use a different optimization rule for the dense-kronecker pattern
self._pipeline._compiler._optimization_registry['layer_shatter'].add_rule(
self._pipeline._compiler._optimization_registry["layer_shatter"].add_rule(
apply_dense_product, signature=DenseKroneckerPattern
)
self._circuit, self._int_sq_circuit = self._build_circuits(
Expand Down Expand Up @@ -332,7 +331,7 @@ def categorical_layer_factory(
num_channels,
num_categories=input_layer_kwargs["num_categories"],
logits_factory=lambda shape: Parameter.from_leaf(
TensorParameter(*shape, initializer=NormalInitializer(0.0, 3e-1))
TensorParameter(*shape, initializer=NormalInitializer(0.0, 1e-1))
),
)

Expand All @@ -347,9 +346,8 @@ def gaussian_layer_factory(
TensorParameter(*shape, initializer=NormalInitializer(0.0, 1.0))
),
stddev_factory=lambda shape: Parameter.from_sequence(
TensorParameter(*shape, initializer=NormalInitializer(0.0, 3e-1)),
ExpParameter(shape),
ClampParameter(shape, vmin=1e-5),
TensorParameter(*shape, initializer=NormalInitializer(0.0, 1e-1)),
ScaledSigmoidParameter(shape, vmin=1e-5, vmax=1.0),
),
)

Expand All @@ -367,7 +365,7 @@ def dense_layer_factory(
num_output_units,
weight_factory=lambda shape: Parameter.from_unary(
ExpParameter(shape),
TensorParameter(*shape, initializer=NormalInitializer(0.0, 3e-1)),
TensorParameter(*shape, initializer=NormalInitializer(0.0, 1e-1)),
),
)

Expand Down Expand Up @@ -413,7 +411,7 @@ def categorical_layer_factory(
num_channels,
num_categories=input_layer_kwargs["num_categories"],
logits_factory=lambda shape: Parameter.from_leaf(
TensorParameter(*shape, initializer=NormalInitializer(0.0, 3e-1))
TensorParameter(*shape, initializer=NormalInitializer(0.0, 1e-1))
),
)

Expand All @@ -428,9 +426,8 @@ def gaussian_layer_factory(
TensorParameter(*shape, initializer=NormalInitializer(0.0, 1.0))
),
stddev_factory=lambda shape: Parameter.from_sequence(
TensorParameter(*shape, initializer=NormalInitializer(0.0, 3e-1)),
ExpParameter(shape),
ClampParameter(shape, vmin=1e-5),
TensorParameter(*shape, initializer=NormalInitializer(0.0, 1e-1)),
ScaledSigmoidParameter(shape, vmin=1e-5, vmax=1.0)
),
)

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
)
parser.add_argument(
"--dtype",
default="float64",
default="float32",
choices=["float32", "float64"],
help="The default Torch dtype to use",
)
Expand Down
1 change: 1 addition & 0 deletions src/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def set_global_seed(seed: int, is_deterministic=True):
if is_deterministic is True:
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
torch._dynamo.config.cache_size_limit = 24


def get_git_revision_hash() -> str:
Expand Down

0 comments on commit 11ec3fe

Please sign in to comment.