Skip to content

Commit

Permalink
slurm_logs now in custom dir
Browse files Browse the repository at this point in the history
  • Loading branch information
smilesun committed Jul 11, 2024
1 parent 054485c commit a4fc6e6
Show file tree
Hide file tree
Showing 35 changed files with 381 additions and 43 deletions.
3 changes: 2 additions & 1 deletion docs/build/html/_modules/domainlab/algos/builder_dann.html
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ <h1 id="modules-domainlab-algos-builder-dann--page-root">Source code for domainl
from domainlab.compos.zoo_nn import FeatExtractNNBuilderChainNodeGetter
from domainlab.models.model_dann import mk_dann
from domainlab.utils.utils_cuda import get_device
from domainlab.utils.hyperparameter_retrieval import get_gamma_reg


<div class="viewcode-block" id="NodeAlgoBuilderDANN"><a class="viewcode-back" href="../../../domainlab.algos.html#domainlab.algos.builder_dann.NodeAlgoBuilderDANN">[docs]</a>class NodeAlgoBuilderDANN(NodeAlgoBuilder):
Expand Down Expand Up @@ -364,7 +365,7 @@ <h1 id="modules-domainlab-algos-builder-dann--page-root">Source code for domainl
model = mk_dann(list_str_y=task.list_str_y,
net_classifier=net_classifier)(
list_d_tr=task.list_domain_tr,
alpha=args.gamma_reg,
alpha=get_gamma_reg(args, 'dann'),
net_encoder=net_encoder,
net_discriminator=net_discriminator,
builder=self)
Expand Down
3 changes: 2 additions & 1 deletion docs/build/html/_modules/domainlab/algos/builder_jigen1.html
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ <h1 id="modules-domainlab-algos-builder-jigen1--page-root">Source code for domai
from domainlab.dsets.utils_wrapdset_patches import WrapDsetPatches
from domainlab.models.model_jigen import mk_jigen
from domainlab.utils.utils_cuda import get_device
from domainlab.utils.hyperparameter_retrieval import get_gamma_reg


<div class="viewcode-block" id="NodeAlgoBuilderJiGen"><a class="viewcode-back" href="../../../domainlab.algos.html#domainlab.algos.builder_jigen1.NodeAlgoBuilderJiGen">[docs]</a>class NodeAlgoBuilderJiGen(NodeAlgoBuilder):
Expand Down Expand Up @@ -365,7 +366,7 @@ <h1 id="modules-domainlab-algos-builder-jigen1--page-root">Source code for domai
model = mk_jigen(
list_str_y=task.list_str_y,
net_classifier=net_classifier)(
coeff_reg=args.gamma_reg,
coeff_reg=get_gamma_reg(args, 'jigen'),
net_encoder=net_encoder,
net_classifier_permutation=net_classifier_perm,
n_perm=args.nperm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,15 @@ <h1 id="modules-domainlab-algos-trainers-a-trainer--page-root">Source code for d
"""
if self._decoratee is not None:
return self._decoratee.dset_decoration_args_algo(args, ddset)
return ddset</div></div>
return ddset</div>

<div class="viewcode-block" id="AbstractTrainer.print_parameters"><a class="viewcode-back" href="../../../../domainlab.algos.trainers.html#domainlab.algos.trainers.a_trainer.AbstractTrainer.print_parameters">[docs]</a> def print_parameters(self):
"""
Function to print all parameters of the object.
Can be used to print the parameters of any child class
"""
params = vars(self)
print(f"Parameters of {type(self).__name__}: {params}")</div></div>
</pre></div>

</article>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ <h1 id="modules-domainlab-algos-trainers-train-dial--page-root">Source code for
from torch.autograd import Variable

from domainlab.algos.trainers.train_basic import TrainerBasic
from domainlab.utils.hyperparameter_retrieval import get_gamma_reg


<div class="viewcode-block" id="TrainerDIAL"><a class="viewcode-back" href="../../../../domainlab.algos.trainers.html#domainlab.algos.trainers.train_dial.TrainerDIAL">[docs]</a>class TrainerDIAL(TrainerBasic):
Expand Down Expand Up @@ -358,7 +359,7 @@ <h1 id="modules-domainlab-algos-trainers-train-dial--page-root">Source code for
tensor_x_adv = self.gen_adversarial(self.device, tensor_x, tensor_y)
tensor_x_batch_adv_no_grad = Variable(tensor_x_adv, requires_grad=False)
loss_dial = self.model.cal_task_loss(tensor_x_batch_adv_no_grad, tensor_y)
return [loss_dial], [self.aconf.gamma_reg]</div>
return [loss_dial], [get_gamma_reg(self.aconf, self.name)]</div>
</pre></div>

</article>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ <h1 id="modules-domainlab-algos-trainers-train-matchdg--page-root">Source code f
)
from domainlab.tasks.utils_task_dset import DsetIndDecorator4XYD
from domainlab.utils.logger import Logger
from domainlab.utils.hyperparameter_retrieval import get_gamma_reg


<div class="viewcode-block" id="TrainerMatchDG"><a class="viewcode-back" href="../../../../domainlab.algos.trainers.html#domainlab.algos.trainers.train_matchdg.TrainerMatchDG">[docs]</a>class TrainerMatchDG(AbstractTrainer):
Expand All @@ -345,7 +346,7 @@ <h1 id="modules-domainlab-algos-trainers-train-matchdg--page-root">Source code f
self.base_domain_size = get_base_domain_size4match_dg(self.task)
self.epo_loss_tr = 0
self.flag_erm = flag_erm
self.lambda_ctr = self.aconf.gamma_reg
self.lambda_ctr = get_gamma_reg(aconf, self.name)
self.mk_match_tensor(epoch=0)
self.flag_match_tensor_sweep_over = False
self.tuple_tensor_ref_domain2each_y = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ <h1 id="modules-domainlab-algos-trainers-train-mldg--page-root">Source code for
from domainlab.algos.trainers.train_basic import TrainerBasic
from domainlab.tasks.utils_task import mk_loader
from domainlab.tasks.utils_task_dset import DsetZip
from domainlab.utils.hyperparameter_retrieval import get_gamma_reg


<div class="viewcode-block" id="TrainerMLDG"><a class="viewcode-back" href="../../../../domainlab.algos.trainers.html#domainlab.algos.trainers.train_mldg.TrainerMLDG">[docs]</a>class TrainerMLDG(AbstractTrainer):
Expand Down Expand Up @@ -417,7 +418,7 @@ <h1 id="modules-domainlab-algos-trainers-train-mldg--page-root">Source code for
loss = (
loss_source_task.sum()
+ source_reg_tr.sum()
+ self.aconf.gamma_reg * loss_look_forward.sum()
+ get_gamma_reg(self.aconf, self.name) * loss_look_forward.sum()
)
#
loss.backward()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ <h1 id="modules-domainlab-algos-trainers-zoo-trainer--page-root">Source code for
from domainlab.algos.trainers.train_matchdg import TrainerMatchDG
from domainlab.algos.trainers.train_mldg import TrainerMLDG
from domainlab.algos.trainers.train_fishr import TrainerFishr
from domainlab.algos.trainers.train_irm import TrainerIRM


<div class="viewcode-block" id="TrainerChainNodeGetter"><a class="viewcode-back" href="../../../../domainlab.algos.trainers.html#domainlab.algos.trainers.zoo_trainer.TrainerChainNodeGetter">[docs]</a>class TrainerChainNodeGetter(object):
Expand Down Expand Up @@ -358,6 +359,7 @@ <h1 id="modules-domainlab-algos-trainers-zoo-trainer--page-root">Source code for
chain = TrainerMatchDG(chain)
chain = TrainerMLDG(chain)
chain = TrainerFishr(chain)
chain = TrainerIRM(chain)
chain = TrainerHyperScheduler(chain)
node = chain.handle(self.request)
head = node
Expand Down
39 changes: 38 additions & 1 deletion docs/build/html/_modules/domainlab/arg_parser.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,37 @@ <h1 id="modules-domainlab-arg-parser--page-root">Source code for domainlab.arg_p
from domainlab.models.args_vae import add_args2parser_vae
from domainlab.utils.logger import Logger

<div class="viewcode-block" id="ParseValuesOrKeyValuePairs"><a class="viewcode-back" href="../../domainlab.html#domainlab.arg_parser.ParseValuesOrKeyValuePairs">[docs]</a>class ParseValuesOrKeyValuePairs(argparse.Action):
"""Class used for arg parsing where values are provided in a key value format"""

def __call__(self, parser: argparse.ArgumentParser,
namespace: argparse.Namespace, values: str, option_string: str = None):
"""
Handle parsing of key value pairs, or a single value instead

Args:
parser (argparse.ArgumentParser): The ArgumentParser object.
namespace (argparse.Namespace): The namespace object to store parsed values.
values (str): The string containing key=value pairs or a single float value.
option_string (str, optional): The option string that triggered this action (unused).

Raises:
ValueError: If the values cannot be parsed to float.
"""
if "=" in values:
my_dict = {}
for kv in values.split(","):
k, v = kv.split("=")
try:
my_dict[k.strip()] = float(v.strip())
except ValueError:
raise ValueError(f"Invalid value in key-value pair: '{kv}', must be float")
setattr(namespace, self.dest, my_dict)
else:
try:
setattr(namespace, self.dest, float(values))
except ValueError:
raise ValueError(f"Invalid value for {self.dest}: '{values}', must be float")</div>

<div class="viewcode-block" id="mk_parser_main"><a class="viewcode-back" href="../../domainlab.html#domainlab.arg_parser.mk_parser_main">[docs]</a>def mk_parser_main():
"""
Expand All @@ -340,7 +371,13 @@ <h1 id="modules-domainlab-arg-parser--page-root">Source code for domainlab.arg_p
parser.add_argument("--lr", type=float, default=1e-4, help="learning rate")

parser.add_argument(
"--gamma_reg", type=float, default=0.1, help="weight of regularization loss"
"--gamma_reg",
default=0.1,
help="weight of regularization loss in the form of $$\ell(\cdot) + \mu \times R(\cdot)$$ \
can specify per model as 'default=3.0, dann=1.0,jigen=2.0', where default refer to gamma for trainer \
note diva is implemented $$\ell(\cdot) + \mu \times R(\cdot)$$ \
so diva does not have gamma_reg",
action=ParseValuesOrKeyValuePairs
)

parser.add_argument("--es", type=int, default=1, help="early stop steps")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ <h1 id="modules-domainlab-exp-protocol-aggregate-results--page-root">Source code

<div class="viewcode-block" id="agg_main"><a class="viewcode-back" href="../../../domainlab.exp_protocol.html#domainlab.exp_protocol.aggregate_results.agg_main">[docs]</a>def agg_main(bm_dir: str, skip_plotting: bool = False):
"""Aggregates partial results and generate plots."""
bm_dir.rstrip("/")
agg_output = f"{bm_dir}/results.csv"
agg_input = f"{bm_dir}/rule_results"
agg_from_directory(agg_input, agg_output)
Expand Down
34 changes: 33 additions & 1 deletion docs/build/html/_modules/domainlab/models/a_model.html
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,39 @@ <h1 id="modules-domainlab-models-a-model--page-root">Source code for domainlab.m
"""
if self._decoratee is not None:
return self._decoratee.dset_decoration_args_algo(args, ddset)
return ddset</div></div>
return ddset</div>

@property
def p_na_prefix(self):
"""
common prefix for Models
"""
return "Model"

@property
def name(self):
"""
get the name of the algorithm
"""
na_prefix = self.p_na_prefix
len_prefix = len(na_prefix)
na_class = type(self).__name__
if na_class[:len_prefix] != na_prefix:
raise RuntimeError(
"Model builder node class must start with ",
na_prefix,
"the current class is named: ",
na_class,
)
return type(self).__name__[len_prefix:].lower()

<div class="viewcode-block" id="AModel.print_parameters"><a class="viewcode-back" href="../../../domainlab.models.html#domainlab.models.a_model.AModel.print_parameters">[docs]</a> def print_parameters(self):
"""
Function to print all parameters of the object.
Can be used to print the parameters of every child class.
"""
params = vars(self)
print(f"Parameters of {type(self).__name__}: {params}")</div></div>
</pre></div>

</article>
Expand Down
6 changes: 4 additions & 2 deletions docs/build/html/_modules/domainlab/models/model_dann.html
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,15 @@ <h1 id="modules-domainlab-models-model-dann--page-root">Source code for domainla
dict_rst = fun_scheduler(
epoch
) # the __call__ method of hyperparameter scheduler
self.alpha = dict_rst["alpha"]
self.alpha = dict_rst[self.name + "_alpha"]

def hyper_init(self, functor_scheduler):
"""hyper_init.
:param functor_scheduler:
"""
return functor_scheduler(trainer=None, alpha=self.alpha)
parameters = {}
parameters[self.name + "_alpha"] = self.alpha
return functor_scheduler(trainer=None, **parameters)

def _cal_reg_loss(self, tensor_x, tensor_y, tensor_d, others):
_ = others
Expand Down
12 changes: 8 additions & 4 deletions docs/build/html/_modules/domainlab/models/model_diva.html
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,22 @@ <h1 id="modules-domainlab-models-model-diva--page-root">Source code for domainla
:param fun_scheduler:
"""
dict_rst = fun_scheduler(epoch)
self.beta_d = dict_rst["beta_d"]
self.beta_y = dict_rst["beta_y"]
self.beta_x = dict_rst["beta_x"]
self.beta_d = dict_rst[self.name + "_beta_d"]
self.beta_y = dict_rst[self.name + "_beta_x"]
self.beta_x = dict_rst[self.name + "_beta_y"]

def hyper_init(self, functor_scheduler):
"""
initiate a scheduler object via class name and things inside this model

:param functor_scheduler: the class name of the scheduler
"""
parameters = {}
parameters[self.name + "_beta_d"] = self.beta_d
parameters[self.name + "_beta_y"] = self.beta_y
parameters[self.name + "_beta_x"] = self.beta_x
return functor_scheduler(
trainer=None, beta_d=self.beta_d, beta_y=self.beta_y, beta_x=self.beta_x
trainer=None, **parameters
)

def _cal_reg_loss(self, tensor_x, tensor_y, tensor_d, others=None):
Expand Down
19 changes: 10 additions & 9 deletions docs/build/html/_modules/domainlab/models/model_hduva.html
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ <h1 id="modules-domainlab-models-model-hduva--page-root">Source code for domainl
dict_rst = fun_scheduler(
epoch
) # the __call__ function of hyper-para-scheduler object
self.beta_d = dict_rst["beta_d"]
self.beta_y = dict_rst["beta_y"]
self.beta_x = dict_rst["beta_x"]
self.beta_t = dict_rst["beta_t"]
self.beta_d = dict_rst[self.name + "_beta_d"]
self.beta_y = dict_rst[self.name + "_beta_y"]
self.beta_x = dict_rst[self.name + "_beta_x"]
self.beta_t = dict_rst[self.name + "_beta_t"]

def hyper_init(self, functor_scheduler):
"""hyper_init.
Expand All @@ -387,12 +387,13 @@ <h1 id="modules-domainlab-models-model-hduva--page-root">Source code for domainl
# calling the constructor of the hyper-parameter-scheduler class, so that this scheduler
# class build a dictionary {"beta_d":self.beta_d, "beta_y":self.beta_y}
# constructor signature is def __init__(self, **kwargs):
parameters = {}
parameters[self.name + "_beta_d"] = self.beta_d
parameters[self.name + "_beta_y"] = self.beta_y
parameters[self.name + "_beta_x"] = self.beta_x
parameters[self.name + "_beta_t"] = self.beta_t
return functor_scheduler(
trainer=None,
beta_d=self.beta_d,
beta_y=self.beta_y,
beta_x=self.beta_x,
beta_t=self.beta_t,
trainer=None, **parameters
)

@store_args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ <h1 id="modules-domainlab-utils-generate-benchmark-plots--page-root">Source code
['param_index','task',' algo',' epos',' te_d',' seed',' params',' acc','precision',...]
"""
os.makedirs(output_dir, exist_ok=True)
obj = dataframe.columns[G_DF_PLOT_COL_METRIC_START:G_DF_PLOT_COL_METRIC_END]
pos_numeric_end = min(G_DF_PLOT_COL_METRIC_END, dataframe.shape[1])
obj = dataframe.columns[G_DF_PLOT_COL_METRIC_START:pos_numeric_end]
# boxplots
for objective in obj:
boxplot(
Expand Down Expand Up @@ -576,7 +577,8 @@ <h1 id="modules-domainlab-utils-generate-benchmark-plots--page-root">Source code
but also between the parameter setups
"""
dataframe = dataframe_in.copy()
index = list(range(G_DF_PLOT_COL_METRIC_START, G_DF_PLOT_COL_METRIC_END))
pos_numeric_end = min(G_DF_PLOT_COL_METRIC_END, dataframe.shape[1])
index = list(range(G_DF_PLOT_COL_METRIC_START, pos_numeric_end))
if distinguish_param_setups:
dataframe_ = dataframe.iloc[:, index]
dataframe_.insert(
Expand All @@ -589,7 +591,8 @@ <h1 id="modules-domainlab-utils-generate-benchmark-plots--page-root">Source code

g_p = sns.pairplot(data=dataframe_, hue="label", corner=True, kind=kind)
else:
index_ = list(range(G_DF_PLOT_COL_METRIC_START, G_DF_PLOT_COL_METRIC_END))
pos_numeric_end = min(G_DF_PLOT_COL_METRIC_END, dataframe.shape[1])
index_ = list(range(G_DF_PLOT_COL_METRIC_START, pos_numeric_end))
index_.insert(0, G_DF_TASK_COL)
dataframe_ = dataframe.iloc[:, index_]

Expand Down Expand Up @@ -726,7 +729,8 @@ <h1 id="modules-domainlab-utils-generate-benchmark-plots--page-root">Source code
else:
dataframe.insert(0, "label", dataframe[COLNAME_METHOD])
# we need "G_DF_PLOT_COL_METRIC_START + 1" as we did insert the columns 'label' at index 0
index = list(range(G_DF_PLOT_COL_METRIC_START + 1, G_DF_PLOT_COL_METRIC_END))
pos_numeric_end = min(G_DF_PLOT_COL_METRIC_END, dataframe.shape[1])
index = list(range(G_DF_PLOT_COL_METRIC_START + 1, pos_numeric_end))
num_lines = len(dataframe["label"].unique())
_, axis = plt.subplots(
figsize=(9, 9 + (0.28 * num_lines)), subplot_kw=dict(polar=True)
Expand Down
2 changes: 2 additions & 0 deletions docs/build/html/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ <h1 id="modules-index--page-root">All modules for which code is available</h1>
<li><a href="domainlab/algos/trainers/train_dial.html">domainlab.algos.trainers.train_dial</a></li>
<li><a href="domainlab/algos/trainers/train_fishr.html">domainlab.algos.trainers.train_fishr</a></li>
<li><a href="domainlab/algos/trainers/train_hyper_scheduler.html">domainlab.algos.trainers.train_hyper_scheduler</a></li>
<li><a href="domainlab/algos/trainers/train_irm.html">domainlab.algos.trainers.train_irm</a></li>
<li><a href="domainlab/algos/trainers/train_matchdg.html">domainlab.algos.trainers.train_matchdg</a></li>
<li><a href="domainlab/algos/trainers/train_mldg.html">domainlab.algos.trainers.train_mldg</a></li>
<li><a href="domainlab/algos/trainers/zoo_trainer.html">domainlab.algos.trainers.zoo_trainer</a></li>
Expand Down Expand Up @@ -417,6 +418,7 @@ <h1 id="modules-index--page-root">All modules for which code is available</h1>
<li><a href="domainlab/utils/generate_benchmark_plots.html">domainlab.utils.generate_benchmark_plots</a></li>
<li><a href="domainlab/utils/get_git_tag.html">domainlab.utils.get_git_tag</a></li>
<li><a href="domainlab/utils/hyperparameter_gridsearch.html">domainlab.utils.hyperparameter_gridsearch</a></li>
<li><a href="domainlab/utils/hyperparameter_retrieval.html">domainlab.utils.hyperparameter_retrieval</a></li>
<li><a href="domainlab/utils/hyperparameter_sampling.html">domainlab.utils.hyperparameter_sampling</a></li>
<li><a href="domainlab/utils/logger.html">domainlab.utils.logger</a></li>
<li><a href="domainlab/utils/override_interface.html">domainlab.utils.override_interface</a></li>
Expand Down
4 changes: 2 additions & 2 deletions docs/build/html/_sources/doc_benchmark.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ hyperparameter sampling and pytorch.
The following script will help to find out which job has failed and the error message, so that you could direct to the
specific log file
```cluster
bash ./sh_list_error.sh ./zoutput/slurm_logs
bash ./sh_list_error.sh ./zoutput/benchmarks/[output folder of the sepcifed benchmark in the yaml file]/slurm_logs
```
#### Map between slurm job id and sampled hyperparameter index
suppose the slurm job id is 14144163, one could the corresponding log file in `./zoutput/slurm_logs` folder via
suppose the slurm job id is 14144163, one could the corresponding log file in `./zoutput/[output folder of the sepcifed benchmark in the yaml file]/slurm_logs` folder via
`find . | grep -i "14144163"`

the results can be
Expand Down
Loading

0 comments on commit a4fc6e6

Please sign in to comment.