Skip to content

Commit

Permalink
fix: bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ofurman committed Aug 17, 2023
1 parent 989f456 commit 6f93dca
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 595 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ logs/**
##########################
# Common files

# VSCode
.vscode/

# IntelliJ
.idea/
*.iml
Expand Down
2 changes: 1 addition & 1 deletion conf/base/catalog/uci_nodeflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ uci_energy_nodeflow_{{i}}.y_test:

uci_energy_nodeflow_{{i}}.hp_search:
type: pandas.CSVDataSet
filepath: gcs://nodeflow/data/07_model_output/UCI/energy/hp_search_concrete_{{i}}.csv
filepath: gcs://nodeflow/data/07_model_output/UCI/energy/hp_search_energy_{{i}}.csv
fs_args:
project: theta-kingdom-385217
credentials: creds_sa
Expand Down
35 changes: 0 additions & 35 deletions conf/base/parameters/modeling/cnf.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#### Models ####
{% for i in range(20) %}
uci_wine_quality_cnf_{{i}}:
model_params:
# loss_function: "MultiRMSE"
# embedding_dim: 40
num_blocks: 3
device: "cpu"

model_hyperparams:
embedding_dim: [0]
hidden_dims: [[32,32], [80, 40]]
Expand All @@ -24,11 +18,6 @@ uci_wine_quality_cnf_{{i}}:

{% for i in range(20) %}
uci_concrete_cnf_{{i}}:
model_params:
# loss_function: "MultiRMSE"
num_blocks: 3
device: "cpu"

model_hyperparams:
embedding_dim: [0]
hidden_dims: [[32,32], [80, 40]]
Expand All @@ -45,11 +34,6 @@ uci_concrete_cnf_{{i}}:

{% for i in range(20) %}
uci_energy_cnf_{{i}}:
model_params:
num_blocks: 3
# loss_function: "MultiRMSE"
device: "cpu"

model_hyperparams:
embedding_dim: [0]
hidden_dims: [[80, 40], [80, 80, 40]]
Expand All @@ -66,10 +50,6 @@ uci_energy_cnf_{{i}}:

{% for i in range(20) %}
uci_kin8nm_cnf_{{i}}:
model_params:
num_blocks: 3
device: "cpu"

model_hyperparams:
embedding_dim: [0]
hidden_dims: [[80, 40], [80, 80, 40]]
Expand All @@ -86,10 +66,6 @@ uci_kin8nm_cnf_{{i}}:

{% for i in range(20) %}
uci_naval_cnf_{{i}}:
model_params:
num_blocks: 3
device: "cpu"
#
model_hyperparams:
embedding_dim: [0]
hidden_dims: [[80, 40], [100, 100, 50]]
Expand All @@ -106,10 +82,6 @@ uci_naval_cnf_{{i}}:

{% for i in range(20) %}
uci_power_plant_cnf_{{i}}:
model_params:
num_blocks: 3
device: "cpu"

model_hyperparams:
embedding_dim: [0]
hidden_dims: [[100, 50], [100, 100, 50], [200, 100, 100, 50]]
Expand All @@ -126,9 +98,6 @@ uci_power_plant_cnf_{{i}}:

{% for i in range(20) %}
uci_protein_cnf_{{i}}:
model_params:
device: "cuda"

model_hyperparams:
num_layers: [6]
depth: [4]
Expand All @@ -148,10 +117,6 @@ uci_protein_cnf_{{i}}:

{% for i in range(20) %}
uci_year_prediction_msd_cnf_{{i}}:
model_params:
device: "cuda"
num_blocks: 3

model_hyperparams:
embedding_dim: [0]
hidden_dims: [[80, 80, 80, 40], [80,40], [80, 80, 40]]
Expand Down
42 changes: 6 additions & 36 deletions conf/base/parameters/modeling/nodeflow.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#### Models ####
{% for i in range(20) %}
uci_wine_quality_nodeflow_{{i}}:
model_params:
# loss_function: "MultiRMSE"
device: "cuda"

model_hyperparams:
num_layers: [6]
depth: [2, 4]
Expand All @@ -25,10 +21,6 @@ uci_wine_quality_nodeflow_{{i}}:

{% for i in range(20) %}
uci_concrete_nodeflow_{{i}}:
model_params:
# loss_function: "MultiRMSE"
device: "cuda"

model_hyperparams:
num_layers: [6, 3]
depth: [4, 2]
Expand All @@ -48,19 +40,15 @@ uci_concrete_nodeflow_{{i}}:

{% for i in range(20) %}
uci_energy_nodeflow_{{i}}:
model_params:
# loss_function: "MultiRMSE"
device: "cuda"

model_hyperparams:
num_layers: [6, 3, 1]
depth: [4, 2, 1]
tree_output_dim: [1]
num_trees: [300, 100, 50]
flow_hidden_dims: [[64,64,64,32], [16,16], [32,32], [16, 16, 16], [32, 32, 32], [64,32], [64,64,32]]
num_layers: [1] #,2,3,4,5,6]
depth: [1] #,2,3,4,5]
tree_output_dim: [1,2]
num_trees: [50, 100] #, 200, 300, 400, 500]
flow_hidden_dims: [[16,16]] #, [32,32], [16, 16, 16], [32, 32, 32]]
#### Training ####

n_epochs: 400
n_epochs: 100
split_size: 0.8
random_seed: 42
batch_size: 2024
Expand All @@ -71,9 +59,6 @@ uci_energy_nodeflow_{{i}}:

{% for i in range(20) %}
uci_naval_nodeflow_{{i}}:
model_params:
device: "cuda"

model_hyperparams:
num_layers: [6]
depth: [4]
Expand All @@ -93,9 +78,6 @@ uci_naval_nodeflow_{{i}}:

{% for i in range(20) %}
uci_power_plant_nodeflow_{{i}}:
model_params:
device: "cuda"

model_hyperparams:
num_layers: [6]
depth: [4]
Expand All @@ -115,9 +97,6 @@ uci_power_plant_nodeflow_{{i}}:

{% for i in range(20) %}
uci_kin8nm_nodeflow_{{i}}:
model_params:
device: "cuda"

model_hyperparams:
num_layers: [6]
depth: [4]
Expand All @@ -137,9 +116,6 @@ uci_kin8nm_nodeflow_{{i}}:

{% for i in range(20) %}
uci_protein_nodeflow_{{i}}:
model_params:
device: "cuda"

model_hyperparams:
num_layers: [6]
depth: [2, 4]
Expand All @@ -159,9 +135,6 @@ uci_protein_nodeflow_{{i}}:

{% for i in range(20) %}
uci_yacht_nodeflow_{{i}}:
model_params:
device: "cuda"

model_hyperparams:
num_layers: [6, 3]
depth: [4, 2, 1]
Expand All @@ -181,9 +154,6 @@ uci_yacht_nodeflow_{{i}}:

{% for i in range(20) %}
uci_year_prediction_msd_nodeflow_{{i}}:
model_params:
device: "cuda"

model_hyperparams:
num_layers: [6]
depth: [4, 2]
Expand Down
57 changes: 18 additions & 39 deletions src/probabilistic_flow_boosting/models/nodeflow/nodeflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,30 @@ def training_step(self, batch, batch_idx):
x, y = batch
logpx = self(x, y)
loss = -logpx.mean()
self.log("train_nll", loss, on_step=False, on_epoch=True, prog_bar=True, logger=True)
self.log("train_nll", loss, on_step=False, on_epoch=True, prog_bar=True, logger=False)
return loss

def validation_step(self, batch, batch_idx):
x, y = batch
logpx = self(x, y)
loss = -logpx.mean()
self.log("val_nll", loss, on_step=False, on_epoch=True, prog_bar=True, logger=True)
self.log("val_nll", loss, on_step=False, on_epoch=True, prog_bar=True, logger=False)

def predict_step(self, batch: Any, num_samples: int = 10) -> Any:
x, y = batch
samples = self._sample(x[0], num_samples)
samples_size = samples.shape
samples = samples.reshape((samples_size[0] * samples_size[1], samples_size[2]))

def configure_optimizers(self) -> Any:
optimizer = optim.RAdam(self.parameters(), lr=0.003)
return optimizer

# @torch.no_grad()
# def _sample(self, X: torch.Tensor, num_samples: int) -> torch.Tensor:
# x = self.tree_model(X)
# x = self.flow_model.sample(x, num_samples=num_samples)
# return x
@torch.no_grad()
def _sample(self, X: torch.Tensor, num_samples: int) -> torch.Tensor:
x = self.tree_model(X)
x = self.flow_model.sample(x, num_samples=num_samples)
return x

# @torch.no_grad()
# def sample(self, X: np.ndarray, num_samples: int = 10, batch_size: int = 128) -> np.ndarray:
Expand Down Expand Up @@ -200,36 +206,9 @@ def configure_optimizers(self) -> Any:
# samples: np.ndarray = samples.squeeze()
# return samples

# @torch.no_grad()
# def predict(
# self, X: np.ndarray, method: str = "mean", num_samples: int = 1000, batch_size: int = 128, **kwargs
# ) -> np.ndarray:
# samples: np.ndarray = self.sample(X=X, num_samples=num_samples, batch_size=batch_size)

# if method == "mean":
# y_pred: np.ndarray = samples.mean(axis=1)
# else:
# raise ValueError(f"Method {method} not supported.")

# y_pred: np.ndarray = np.array(y_pred)
# return y_pred

# def predict_tree_path(self, X: np.ndarray):
# """Method for predicting the tree path from Soft Decision Tree component."""
# X: torch.Tensor = torch.as_tensor(data=X, dtype=torch.float, device=self.device)
# paths, _ = self.tree_model(X)
# paths: np.ndarray = paths.detach().cpu().numpy()
# return paths

# def _save_temp(self, mid: str):
# torch.save(self, f"/tmp/model_{mid}.pt")

# def _load_temp(self, mid: str):
# return torch.load(f"/tmp/model_{mid}.pt")

# def save(self, filename: str):
# torch.save(self, f"{filename}-nodeflow.pt")
def save(self, filename: str):
torch.save(self, f"{filename}-nodeflow.pt")

# @classmethod
# def load(cls, filename: str):
# return torch.load(f"{filename}-nodeflow.pt")
@classmethod
def load(cls, filename: str):
return torch.load(f"{filename}-nodeflow.pt")
Loading

0 comments on commit 6f93dca

Please sign in to comment.