Configuration#
Hyrax ships with a complete default configuration file that can be used immediately to run the software, however, to make the most of Hyrax you’ll need to modify the configuration to suit your specific needs. For a deeper look at how configuration files are layered and resolved, see The Hyrax Configuration System.
Using the configuration system#
When creating an instance of a Hyrax object in a notebook or running hyrax
from the command line, the configuration is the primary method for specifying the parameters.
If no configuration file is specified, the default
will be used. To specify a different configuration file, use the
-c | --runtime-config flag from the CLI
or pass the path to the configuration file when creating a Hyrax object.
from hyrax import Hyrax
# Create an instance of the Hyrax object
f = Hyrax(config_file=<path_to_config_file.toml>)
# Train the model specified in the configuration file
f.train()
>> hyrax train -c <path_to_config_file.toml>
Your first custom configuration#
You could create a copy of the entire default configuration file and modify it to suit your needs, however that’s typically not required because often there are only a few parameters that must be updated for any given Hyrax action.
If a specific configuration file is provided, Hyrax will combine it with the default configuration and overwrite the default values with the specific ones.
For example, if a file called my_config.toml had the following contents:
1[general]
2 log_level = "debug"
It could be used to override the default log_level configuration, while leaving
the rest of the configuration unchanged.
from hyrax import Hyrax
# Create an instance of the Hyrax object
f = Hyrax(config_file=my_config.toml)
# Train the model specified in the configuration file
f.train()
>> hyrax train -c my_config.toml
Updating settings in a notebook#
Additionally, Hyrax supports modification of the configuration interactively in a notebook.
from hyrax import Hyrax
# Create a Hyrax instance, implicitly using the default configuration
f = Hyrax()
# Set the log level for the Hyrax instance config
f.config['general']['log_level'] = 'debug'
# Train the model specified in the configuration file
f.train()
Immutable configurations#
Once Hyrax begins running an action, the configuration becomes immutable. This means that the configuration cannot be changed during the execution of an action, and attempting to do so in code will raise an exception.
By making the configuration immutable during execution, we ensure that the state of all parameters can be accurately saved with the results of the action. This runtime snapshot is especially helpful when comparing runs in Model comparison.
About the default configuration#
The default configuration for Hyrax contains safe default values for all of the settings that Hyrax uses. A portion of the default configuration file is shown below.
Note
Only the first portion of the default configuration file is shown below. The entire file can be found at the bottom of the page here: Complete default configuration file.
1[general]
2# Set to `true` during development to skip checking for default config values
3# in external libraries. Use `false` otherwise.
4dev_mode = false
5
6# Destination of log messages. Options: 'stderr', 'stdout' specify the console,
7# "path/to/hyrax.log" specifies a file.
8log_destination = "stderr"
9
10# Lowest log level to emit. Options: "critical", "error", "warning", "info", "debug".
11log_level = "info"
12
13# Directory where data is stored.
14data_dir = "./data"
15
16#Top level directory for writing results.
17results_dir = "./results"
18
19
20[download]
21# Cut out width in arcseconds.
22sw = "22asec"
23
24# Cut out height in arcseconds.
25sh = "22asec"
There is a lot of information there, but don’t worry, we’ll break it down for you.
First, the file formatted using TOML for its easy readability and because it is one of the few markdown languages that natively support comments. TOML files are organized into “tables”, and each table contains one or more key/value pairs.
For instance the [general] table (the first table in the config)
contains several keys including log_level and results_dir.
Each of those keys has a value associated with it.
e.g. log_level = "info".
Second, every key has an associated comment describing what the key does. We attempt to keep the comments as concise as possible.
Finally, the configuration file is organized into tables that roughly correspond
to the different actions that Hyrax can take.
For instance, the [train] table contains parameters needed when training a
model such as epochs and weights_filename.
While the [infer] table contains keys such as model_weights_file.
See Hyrax Verbs for the full list of actions these tables correspond to.
Complete default configuration file#
1[general]
2# Set to `true` during development to skip checking for default config values
3# in external libraries. Use `false` otherwise.
4dev_mode = false
5
6# Destination of log messages. Options: 'stderr', 'stdout' specify the console,
7# "path/to/hyrax.log" specifies a file.
8log_destination = "stderr"
9
10# Lowest log level to emit. Options: "critical", "error", "warning", "info", "debug".
11log_level = "info"
12
13# Directory where data is stored.
14data_dir = "./data"
15
16#Top level directory for writing results.
17results_dir = "./results"
18
19
20[download]
21# Cut out width in arcseconds.
22sw = "22asec"
23
24# Cut out height in arcseconds.
25sh = "22asec"
26
27# The filters to download.
28filter = ["HSC-G", "HSC-R", "HSC-I", "HSC-Z", "HSC-Y"]
29
30# The type of data to download.
31type = "coadd"
32
33# The data release to download from.
34rerun = "pdr3_wide"
35
36# Path to credentials.ini file for the downloader. File contents should be:
37# username = "<your username>"
38# password = "<your password>"
39credentials_file = "./credentials.ini"
40
41# Alternate way to pass credentials to the downloader. Users should prefer a
42# credentials.ini file to avoid exposing credentials with source control.
43username = false
44password = false
45
46# The number of sources to download from the catalog. Default is -1, which
47# downloads all sources in the catalog.
48num_sources = -1
49
50# The number of concurrent connections to use when downloading data.
51concurrent_connections = 4
52
53# The number of seconds between printing download statistics.
54stats_print_interval = 60
55
56# The path to the catalog file that defines which cutouts to download.
57fits_file = "./catalog.fits"
58
59# The number of seconds to wait before retrying a failed HTTP request in seconds.
60retry_wait = 30
61
62# How many times to retry a failed HTTP request before moving on to the next one.
63retries = 3
64
65# Number of seconds to wait for a full HTTP response from the server.
66timeout = 3600
67
68# The number of sky location rectangles should we request in a single request.
69chunk_size = 990
70
71# Request the image layer from the cutout service
72image = true
73
74# Request the variance layer from the cutout service
75variance = false
76
77# Request the mask layer from the cutout service
78mask = false
79
80
81[model]
82# NOTE: All parameters are NOT used by all models. Check the model code before training.
83
84# The name of the model to use. Option are a built-in model class name or import path
85# to an external model. e.g. "HyraxAutoencoder", "user_pkg.model.ExternalModel"
86name = ""
87
88
89[model.HyraxAutoencoder]
90# The number of output channels from the first layer.
91base_channel_size = 32
92
93# The length of the latent space vector.
94latent_dim = 64
95
96
97[model.HyraxAutoencoderV2]
98# The number of output channels from the first layer.
99base_channel_size = 32
100
101# The length of the latent space vector.
102latent_dim = 64
103
104# The activation function of the final layer.
105final_layer = "tanh"
106
107[model.ImageDCAE]
108# The number of output channels from the first layer.
109base_channel_size = 32
110
111# The length of the latent space vector.
112latent_dim = 512
113
114# The activation function of the final layer.
115final_layer = "identity"
116
117
118[model.SimCLR]
119# The dimension of the projection head for SimCLR
120projection_dimension = 128
121
122# The scalar temperature parameter for its loss function, NTXentLoss, for SimCLR
123temperature = 0.5
124
125# The probability of applying horizontal flip augmentation for SimCLR
126horizontal_flip_probability = 0.5
127
128# The parameters for color jitter augmentation for SimCLR
129# [brightness, contrast, saturation, hue]
130color_jitter_params = [0.8, 0.8, 0.8, 0.2]
131
132# The probability of applying color jitter augmentation for SimCLR
133color_jitter_probability = 0.8
134
135# The probability of applying grayscale augmentation for SimCLR
136grayscale_probability = 0.2
137
138# The kernel size of Gaussian blur augmentation for SimCLR
139gaussian_blur_kernel_size = 9
140
141# The sigma range used in Gaussian blur augmentation for SimCLR
142gaussian_blur_sigma_range = [0.1, 2.0]
143
144
145[model.HyraxCNN]
146# The number of classes to predict as the output of the model. i.e. 2 would be a
147# binary classifer, 10 would predict the 10 classes in the CiFAR dataset.
148output_classes = 10
149
150
151[criterion]
152# The name of the built-in criterion to use or the import path to an external criterion
153name = "torch.nn.CrossEntropyLoss"
154
155# Whether to "sum" or "mean" loss across channels. Only used by HyraxAutoencoderV2
156band_loss_reduction = "mean"
157
158
159[optimizer]
160# The name of the built-in optimizer to use or the import path to an external optimizer
161name = "torch.optim.SGD"
162
163
164["torch.optim.SGD"]
165# learning rate for torch.optim.SGD optimizer.
166lr = 0.01
167
168# momentum for torch.optim.SGD optimizer.
169momentum = 0.9
170
171["torch.optim.Adam"]
172# learning rate for torch.optim.SGD optimizer.
173lr = 0.01
174
175[scheduler]
176# name of the learning rate scheduler
177# With gamma=1, ExponentialLR will keep the learning rate constant
178# https://docs.pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ExponentialLR.html
179name = "torch.optim.lr_scheduler.ExponentialLR"
180
181["torch.optim.lr_scheduler.ExponentialLR"]
182# the decay multipler on each epoch
183gamma = 1
184
185["torch.optim.lr_scheduler.ConstantLR"]
186
187last_epoch = -1
188
189[train]
190# The name of the file were the model weights will be saved after training.
191weights_filename = "example_model.pth"
192
193#The number of epochs to train for.
194epochs = 10
195
196# If resuming from a check point, set to the path of the checkpoint file.
197# Otherwise set to `false` to start training from the beginning.
198resume = false
199
200# Path to a pre-trained model weights file to use as the starting point for fine-tuning.
201# If `false`, training starts from randomly initialized weights. Cannot be set with `resume`.
202model_weights_file = false
203
204# The data_set split to use when training a model.
205split = "train"
206
207# The name of the experiment when logging training results to mlflow
208experiment_name = "notebook"
209
210# The name of the run when logging training results to mlflow.
211# If false, uses result directory string, <timestamp>-train-<uid>, as run name.
212run_name = false
213
214
215[test]
216# The path to the model weights file to use for testing. If `false`, the most recent
217# training results (from [train]) will be used.
218model_weights_file = false
219
220# The name of the experiment when logging test results to mlflow.
221# If not set, uses the experiment name from [train].
222experiment_name = "notebook"
223
224# The name of the run when logging test results to mlflow.
225# If false, uses result directory string, <timestamp>-test-<uid>, as run name.
226run_name = false
227
228
229
230[onnx]
231
232# The operator set version to use when exporting a model. See the following for info:
233# https://onnxruntime.ai/docs/reference/compatibility.html#onnx-opset-support
234opset_version = 20
235
236# The directory to find input model files to convert to ONNX. ONNX-ified models
237# will be written to this directory as well.
238input_model_directory = false
239
240
241# [data_request]
242# Top-level table that defines the dataset(s) used for training, validation, and inference.
243# Configure with [data_request.train], [data_request.validate], or [data_request.infer] sections.
244
245# [model_inputs]
246# DEPRECATED: Use [data_request] instead. This will be removed in the next major release.
247
248
249[data_set]
250# Crop pixel dimensions for images, e.g., [100, 100]. If false, scans for the
251# smallest image size in [general].data_dir and uses it.
252crop_to = false
253
254# Used by HSCDataset, LSSTDataset, and DownloadedLSSTDataset.
255# Limit to only particular filters. When `false`, use all filters.
256# Options: ["HSC-G", "HSC-R", "HSC-I", "HSC-Z", "HSC-Y"] for HSC
257# Options: ["u", "g", "r", "i", "z" , "y"] for LSST
258filters = false
259
260# Path to a fits file that specifies object IDs to use from the data stored in
261# [general].data_dir. Implementation is data_set class dependent. Use `false` for no filtering.
262filter_catalog = false
263
264# The transformation to be applied to images before being passed on to the model
265# This must be a valid Numpy function. Passing false will result in no transformations
266# (other than cropping) be applied to the images.
267transform = "tanh"
268
269# train_size, validation_size, and test_size use these conventions:
270# * A `float` between `0.0` and `1.0` is the proportion of the dataset to include in the split.
271# * An `int`, represents the absolute number of samples in the particular split.
272# * It is an error for these values to add to more than 1.0 as ratios or the size
273# of the dataset if expressed as integers.
274
275# Size of the train split. If `false`, the value is automatically set to the
276# complement of test_size plus validate_size (if any).
277train_size = 0.6
278
279# Size of the validation split. If `false`, and both train_size and test_size
280# are defined, the value is set to the complement of the other two sizes summed.
281# If `false`, and only one of the other sizes is defined, no validate split is created.
282validate_size = 0.2
283
284# Size of the test split. If `false`, the value is set to the complement of train_size plus
285# the validate_size (if any). If `false` and `train_size = false`, test_size is set to `0.25`.
286test_size = 0.2
287
288# Number to seed with for generating a random split. Use `false` to seed from a
289# system source at runtime.
290seed = false
291
292# If `true`, cache samples in memory during training to reduce runtime after the
293# first epoch. Set to `false` when running inference or on memory-constrained systems.
294use_cache = true
295
296# If `true`, preload the in memory cache using many worker threads when the dataset is constructed
297# to reduce the effect of filesystem latency on first epoch runtime.
298# Warning: Only suitable for situations where the entire dataset fits in system memory
299preload_cache = false
300
301# Number of threads to use for cache preload. cache preload is most effective when your dataset has many small
302# files. The optimal number for this is experimentally determined, and only affects your first epoch of
303# training (or only epoch of inference).
304# If cache preloading is using all of your CPU when enabled, lower this number
305# If cache preloading is not making epoch 1 appreciably faster when enabled, increase this number.
306preload_threads = 50
307
308# Override the name of the object_id column for FitsImageDataset, HSCDataset and DownloadedLSSTDataset
309object_id_column_name = false
310
311# Override the name of the filter column for FitsImageDataset and HSCDataset
312filter_column_name = false
313
314# Override the name of the filename column for FitsImageDataset and HSCDataset
315filename_column_name = false
316
317# Replace NaN in input data with a value, modes are false for no replacement or "quantile" to replace with a
318# defined quantile of the non-NaN data, see nan_quantile.
319nan_mode = false
320
321# When replacing NaN values with a quantile, which quantile in the non-nan tensor should be used.
322nan_quantile = 0.05
323
324# The astropy table to use as a catalog in LSSTDataset and friends
325astropy_table = false
326
327# Semi width in degrees of cutouts made from the butler (17 arcsec)
328semi_width_deg = 0.00472
329
330# Semi height in degrees of cutouts made from the butler (17 arcsec)
331semi_height_deg = 0.00472
332
333
334[data_set.HyraxCifarDataset]
335# If `true`, download CIFAR10 training set, otherwise download test set.
336use_training_data = true
337
338
339[data_set.HyraxRandomDataset]
340# Total number of samples produced by the random dataset
341size = 100
342
343# The dimensions of the numpy arrays that will be produced for each sample represented
344# as a list where each element is the size of dimension.
345shape = [2,5,5]
346
347# Seed to use for random number generation
348seed = 42
349
350# If a list is provided, the data will have randomly labeled with values from the list
351# If set to false, no labels will be included with the data.
352provided_labels = [0, 1, 2]
353
354# List of metadata field names. These will be populated with dummy data.
355metadata_fields = ["meta_field_1", "meta_field_2"]
356
357# Set this to a positive integer to randomly replace some values with an "invalid" value.
358number_invalid_values = 0
359
360# The value to use for invalid values in the data. Must be one of the following:
361# "nan", "inf", "-inf", "none" or a float value.
362invalid_value_type = "nan"
363
364[data_set.MultimodalUniverseDataset]
365# Hugging Face split name to load (for example: "train", "validation", or "test").
366split = "train"
367
368# Maximum number of rows to load from the split. Set to false for no explicit limit.
369max_samples = 100
370
371# Stream rows from Hugging Face instead of downloading full files.
372# If true, `max_samples` must be set.
373streaming = true
374
375
376[data_loader]
377# The number of data points to load at once.
378batch_size = 512
379
380# STRONG RECOMMENDATION: Leave this as `false`.
381# Ensure that the data loader does no secondary shuffling of the data.
382shuffle = false
383
384
385[infer]
386# The path to the model weights file to use for inference.
387model_weights_file = false
388
389# >>> I believe that we can simply remove this entry <<<<<<<<<<<<<<<<<<<<<<<<<<<
390# The data_set split to use for inference. Use `false` for entire dataset.
391split = "infer"
392
393
394[vector_db]
395# The type of vector db to use. Use "false" to disable vector database.
396name = "chromadb"
397
398# The directory where the vector database will be stored. Use "false" to create
399# a new vector database in a timestamped directory. Otherwise set to a path.
400vector_db_dir = false
401
402# The path to inference results. Setting to "false" will use the most recent
403# inference results.
404infer_results_dir = false
405
406
407[vector_db.chromadb]
408# The approximate maximum size of a shard before creating a new one. A smaller
409# value will decrease insert times while increasing search times.
410shard_size_limit = 65536
411
412# Inserting vectors with more than this many elements logs a warning message. ChromaDB
413# performance degrades with vectors of this size. Set to "false" to disable warning.
414vector_size_warning = 10000
415
416
417[vector_db.qdrant]
418# The number of elements in the vectors that will be stored in the vector database.
419# This must be the same as the size of the vectors produced by the model.
420vector_size = 64
421
422
423[results]
424# Path to inference results to use for visualization and lookups. Uses latest inference run if none provided.
425inference_dir = false
426
427
428[umap]
429# Number of data points used to fit the umap transform.
430fit_sample_size = 1024
431
432# Save the fitted umap as a pickle file
433save_fit_umap = true
434
435# Use multiprocessing during transforming to umap space (More memory intensive)
436parallel = false
437
438# Name of the umap implementation to use
439name = "umap.UMAP"
440
441
442[umap.UMAP]
443# Specify any parameter accepted by https://umap-learn.readthedocs.io/en/latest/api.html#umap
444# Dimension of the embedded space
445n_components = 2
446
447# Controls how UMAP balances local versus global structure in the data.
448# See official documentation for details.
449n_neighbors = 15
450
451
452[visualize]
453
454# List of metadata field names to use in visualizer. Must be available as metadata in your dataset
455fields = []
456
457# Whether to display a panel of randomly chosen images corresponding to the selected points
458display_images = false
459
460# Name of catalog column to use for coloring points in the scatter plot. Use false for no coloring.
461color_column = false
462
463# Colormap to use for coloring points in the scatter plot when color_column is specified
464cmap = "viridis"
465
466# Only valid for .pt tensor images. Which bands should be loaded for display
467# [0,3,5] would map bands in that order to R,G,B. Single band will be grayscale.
468torch_tensor_bands = [3]
469
470# Whether to rasterize plot. Will break coloring (Haloviews Bug)
471# Helpful to reduce lag in large datasets.
472rasterize_plot = false
473
474
475[engine]
476
477# The directory containing the ONNX model used for inference in production
478model_directory = false