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# Use multiple GPUs if available
20# Set to `false` by default for development purposes for now
21distributed = false
22
23[download]
24# Cut out width in arcseconds.
25sw = "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# Use multiple GPUs if available
20# Set to `false` by default for development purposes for now
21distributed = false
22
23[download]
24# Cut out width in arcseconds.
25sw = "22asec"
26
27# Cut out height in arcseconds.
28sh = "22asec"
29
30# The filters to download.
31filter = ["HSC-G", "HSC-R", "HSC-I", "HSC-Z", "HSC-Y"]
32
33# The type of data to download.
34type = "coadd"
35
36# The data release to download from.
37rerun = "pdr3_wide"
38
39# Path to credentials.ini file for the downloader. File contents should be:
40# username = "<your username>"
41# password = "<your password>"
42credentials_file = "./credentials.ini"
43
44# Alternate way to pass credentials to the downloader. Users should prefer a
45# credentials.ini file to avoid exposing credentials with source control.
46username = false
47password = false
48
49# The number of sources to download from the catalog. Default is -1, which
50# downloads all sources in the catalog.
51num_sources = -1
52
53# The number of concurrent connections to use when downloading data.
54concurrent_connections = 4
55
56# The number of seconds between printing download statistics.
57stats_print_interval = 60
58
59# The path to the catalog file that defines which cutouts to download.
60fits_file = "./catalog.fits"
61
62# The number of seconds to wait before retrying a failed HTTP request in seconds.
63retry_wait = 30
64
65# How many times to retry a failed HTTP request before moving on to the next one.
66retries = 3
67
68# Number of seconds to wait for a full HTTP response from the server.
69timeout = 3600
70
71# The number of sky location rectangles should we request in a single request.
72chunk_size = 990
73
74# Request the image layer from the cutout service
75image = true
76
77# Request the variance layer from the cutout service
78variance = false
79
80# Request the mask layer from the cutout service
81mask = false
82
83
84[model]
85# NOTE: All parameters are NOT used by all models. Check the model code before training.
86
87# The name of the model to use. Option are a built-in model class name or import path
88# to an external model. e.g. "HyraxAutoencoder", "user_pkg.model.ExternalModel"
89name = ""
90
91
92[model.HyraxAutoencoder]
93# The number of output channels from the first layer.
94base_channel_size = 32
95
96# The length of the latent space vector.
97latent_dim = 64
98
99
100[model.HyraxAutoencoderV2]
101# The number of output channels from the first layer.
102base_channel_size = 32
103
104# The length of the latent space vector.
105latent_dim = 64
106
107# The activation function of the final layer.
108final_layer = "tanh"
109
110[model.ImageDCAE]
111# The number of output channels from the first layer.
112base_channel_size = 32
113
114# The length of the latent space vector.
115latent_dim = 512
116
117# The activation function of the final layer.
118final_layer = "identity"
119
120
121[model.SimCLR]
122# The dimension of the projection head for SimCLR
123projection_dimension = 128
124
125# The scalar temperature parameter for its loss function, NTXentLoss, for SimCLR
126temperature = 0.5
127
128# The probability of applying horizontal flip augmentation for SimCLR
129horizontal_flip_probability = 0.5
130
131# The parameters for color jitter augmentation for SimCLR
132# [brightness, contrast, saturation, hue]
133color_jitter_params = [0.8, 0.8, 0.8, 0.2]
134
135# The probability of applying color jitter augmentation for SimCLR
136color_jitter_probability = 0.8
137
138# The probability of applying grayscale augmentation for SimCLR
139grayscale_probability = 0.2
140
141# The kernel size of Gaussian blur augmentation for SimCLR
142gaussian_blur_kernel_size = 9
143
144# The sigma range used in Gaussian blur augmentation for SimCLR
145gaussian_blur_sigma_range = [0.1, 2.0]
146
147
148[model.HyraxCNN]
149# The number of classes to predict as the output of the model. i.e. 2 would be a
150# binary classifer, 10 would predict the 10 classes in the CiFAR dataset.
151output_classes = 10
152
153
154[criterion]
155# The name of the built-in criterion to use or the import path to an external criterion
156name = "torch.nn.CrossEntropyLoss"
157
158# Whether to "sum" or "mean" loss across channels. Only used by HyraxAutoencoderV2
159band_loss_reduction = "mean"
160
161
162[optimizer]
163# The name of the built-in optimizer to use or the import path to an external optimizer
164name = "torch.optim.SGD"
165
166
167["torch.optim.SGD"]
168# learning rate for torch.optim.SGD optimizer.
169lr = 0.01
170
171# momentum for torch.optim.SGD optimizer.
172momentum = 0.9
173
174["torch.optim.Adam"]
175# learning rate for torch.optim.SGD optimizer.
176lr = 0.01
177
178[scheduler]
179# name of the learning rate scheduler
180# With gamma=1, ExponentialLR will keep the learning rate constant
181# https://docs.pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ExponentialLR.html
182name = "torch.optim.lr_scheduler.ExponentialLR"
183
184["torch.optim.lr_scheduler.ExponentialLR"]
185# the decay multipler on each epoch
186gamma = 1
187
188["torch.optim.lr_scheduler.ConstantLR"]
189
190last_epoch = -1
191
192[train]
193# The name of the file were the model weights will be saved after training.
194weights_filename = "example_model.pth"
195
196#The number of epochs to train for.
197epochs = 10
198
199# If resuming from a check point, set to the path of the checkpoint file.
200# Otherwise set to `false` to start training from the beginning.
201resume = false
202
203# Path to a pre-trained model weights file to use as the starting point for fine-tuning.
204# If `false`, training starts from randomly initialized weights. Cannot be set with `resume`.
205model_weights_file = false
206
207# The data_set split to use when training a model.
208split = "train"
209
210# The name of the experiment when logging training results to mlflow
211experiment_name = "notebook"
212
213# The name of the run when logging training results to mlflow.
214# If false, uses result directory string, <timestamp>-train-<uid>, as run name.
215run_name = false
216
217# If true, shuffle training samples each epoch. Only the train verb uses this option.
218shuffle = true
219
220
221[test]
222# The path to the model weights file to use for testing. If `false`, the most recent
223# training results (from [train]) will be used.
224model_weights_file = false
225
226# The name of the experiment when logging test results to mlflow.
227# If not set, uses the experiment name from [train].
228experiment_name = "notebook"
229
230# The name of the run when logging test results to mlflow.
231# If false, uses result directory string, <timestamp>-test-<uid>, as run name.
232run_name = false
233
234
235
236[onnx]
237
238# The operator set version to use when exporting a model. See the following for info:
239# https://onnxruntime.ai/docs/reference/compatibility.html#onnx-opset-support
240opset_version = 20
241
242# The directory to find input model files to convert to ONNX. ONNX-ified models
243# will be written to this directory as well.
244input_model_directory = false
245
246
247# [data_request]
248# Top-level table that defines the dataset(s) used for training, validation, and inference.
249# Configure with [data_request.train], [data_request.validate], or [data_request.infer] sections.
250
251
252[data_set]
253# Crop pixel dimensions for images, e.g., [100, 100]. If false, scans for the
254# smallest image size in [general].data_dir and uses it.
255crop_to = false
256
257# Used by HSCDataset, LSSTDataset, and DownloadedLSSTDataset.
258# Limit to only particular filters. When `false`, use all filters.
259# Options: ["HSC-G", "HSC-R", "HSC-I", "HSC-Z", "HSC-Y"] for HSC
260# Options: ["u", "g", "r", "i", "z" , "y"] for LSST
261filters = false
262
263# Path to a fits file that specifies object IDs to use from the data stored in
264# [general].data_dir. Implementation is data_set class dependent. Use `false` for no filtering.
265filter_catalog = false
266
267# The transformation to be applied to images before being passed on to the model
268# This must be a valid Numpy function. Passing false will result in no transformations
269# (other than cropping) be applied to the images.
270transform = "tanh"
271
272# Number to seed with for generating a random split. Use `false` to seed from a
273# system source at runtime.
274seed = false
275
276# If `true`, cache samples in memory during training to reduce runtime after the
277# first epoch. Set to `false` when running inference or on memory-constrained systems.
278use_cache = true
279
280
281# Override the name of the object_id column for FitsImageDataset, HSCDataset and DownloadedLSSTDataset
282object_id_column_name = false
283
284# Override the name of the filter column for FitsImageDataset and HSCDataset
285filter_column_name = false
286
287# Override the name of the filename column for FitsImageDataset and HSCDataset
288filename_column_name = false
289
290# Replace NaN in input data with a value, modes are false for no replacement or "quantile" to replace with a
291# defined quantile of the non-NaN data, see nan_quantile.
292nan_mode = false
293
294# When replacing NaN values with a quantile, which quantile in the non-nan tensor should be used.
295nan_quantile = 0.05
296
297# The astropy table to use as a catalog in LSSTDataset and friends
298astropy_table = false
299
300# Semi width in degrees of cutouts made from the butler (17 arcsec)
301semi_width_deg = 0.00472
302
303# Semi height in degrees of cutouts made from the butler (17 arcsec)
304semi_height_deg = 0.00472
305
306
307[data_set.HyraxCifarDataset]
308# If `true`, download CIFAR10 training set, otherwise download test set.
309use_training_data = true
310
311
312[data_set.HyraxRandomDataset]
313# Total number of samples produced by the random dataset
314size = 100
315
316# The dimensions of the numpy arrays that will be produced for each sample represented
317# as a list where each element is the size of dimension.
318shape = [2,5,5]
319
320# Seed to use for random number generation
321seed = 42
322
323# If a list is provided, the data will have randomly labeled with values from the list
324# If set to false, no labels will be included with the data.
325provided_labels = [0, 1, 2]
326
327# List of metadata field names. These will be populated with dummy data.
328metadata_fields = ["meta_field_1", "meta_field_2"]
329
330# Set this to a positive integer to randomly replace some values with an "invalid" value.
331number_invalid_values = 0
332
333# The value to use for invalid values in the data. Must be one of the following:
334# "nan", "inf", "-inf", "none" or a float value.
335invalid_value_type = "nan"
336
337[data_set.HyraxHATSDataset]
338# Extra keyword arguments passed directly to lsdb.open_catalog
339[data_set.HyraxHATSDataset.open_catalog_kwargs]
340
341[data_set.NestedPandasDataset]
342# Extra keyword arguments passed directly to the selected nested_pandas reader.
343[data_set.NestedPandasDataset.read_kwargs]
344# engine = "auto" # pandas default, but can be "pyarrow", "fastparquet"
345# See pandas.read_parquet API reference for all possible arguments.
346
347[data_set.LanceDBDataset]
348# Table name to open inside the LanceDB database.
349table_name = false
350
351# Extra keyword arguments passed directly to lancedb.connect.
352[data_set.LanceDBDataset.connect_kwargs]
353
354# Extra keyword arguments passed directly to db.open_table.
355[data_set.LanceDBDataset.open_table_kwargs]
356
357[data_set.MultimodalUniverseDataset]
358# Hugging Face split name to load (for example: "train", "validation", or "test").
359split = "train"
360
361# Maximum number of rows to load from the split. Set to false for no explicit limit.
362max_samples = 100
363
364# Stream rows from Hugging Face instead of downloading full files.
365# If true, `max_samples` must be set.
366streaming = true
367
368
369[data_set.KafkaStreamDataset]
370# Kafka bootstrap broker address.
371bootstrap_servers = "localhost:9092"
372
373# List of Kafka topics to consume. Must be set, `[]` raises at runtime. A single
374# topic string is accepted for convenience, and will be converted to a list of one topic.
375topics = []
376
377# Kafka consumer group id.
378group_id = "hyrax-infer-stream"
379
380# Where to start consuming when the group has no committed offset: "latest" or "earliest".
381auto_offset_reset = "earliest"
382
383# Seconds to block on each Kafka poll while waiting for a message.
384poll_timeout = 1.0
385
386# Maximum seconds to wait before flushing a partial (smaller than batch_size) batch.
387batch_flush_timeout = 5.0
388
389# Provided path credentials file for a `confluent_kafka` consumer instance
390# e.g.
391# "sasl.username" = <USER_NAME>
392# "sasl.password" = <PASSWORD>
393# "security.protocol" = "SASL_PLAINTEXT"
394# "sasl.mechanism" = "SCRAM-SHA-512"
395credentials_file = false
396
397
398[data_loader]
399# The number of data points to load at once.
400batch_size = 512
401
402
403[infer]
404# The path to the model weights file to use for inference.
405model_weights_file = false
406
407
408[infer_stream]
409# Path to model weights. If false, uses the most recent training results.
410model_weights_file = false
411
412# Save the results of inference in the timestamped result directory.
413save_model_output = false
414
415
416[vector_db]
417# The type of vector db to use. Use "false" to disable vector database.
418name = "chromadb"
419
420# The directory where the vector database will be stored. Use "false" to create
421# a new vector database in a timestamped directory. Otherwise set to a path.
422vector_db_dir = false
423
424# The path to inference results. Setting to "false" will use the most recent
425# inference results.
426infer_results_dir = false
427
428
429[vector_db.chromadb]
430# The approximate maximum size of a shard before creating a new one. A smaller
431# value will decrease insert times while increasing search times.
432shard_size_limit = 65536
433
434# Inserting vectors with more than this many elements logs a warning message. ChromaDB
435# performance degrades with vectors of this size. Set to "false" to disable warning.
436vector_size_warning = 10000
437
438
439[vector_db.qdrant]
440# The number of elements in the vectors that will be stored in the vector database.
441# This must be the same as the size of the vectors produced by the model.
442vector_size = 64
443
444
445[results]
446# Path to inference results to use for visualization and lookups. Uses latest inference run if none provided.
447inference_dir = false
448
449
450[reduce]
451# Name of the reduction algorithm to use
452algorithm = "umap"
453
454# Save the fitted reducer model as a pickle file
455save_fit_model = true
456
457# The number of data points to use when transforming with reduction algorithm at once
458batch_size = 1024
459
460# Use multiprocessing during transforming with redudction algorithm (More memory intensive)
461parallel = false
462
463
464[reduce.umap]
465# Number of data points used to fit the umap model.
466fit_sample_size = 1024
467
468# Path to a pre-existing umap reducer model
469model_path = false
470
471
472[reduce.umap.kwargs]
473# Specify any parameter accepted by https://umap-learn.readthedocs.io/en/latest/api.html#umap
474# Dimension of the embedded space
475n_components = 2
476
477# Controls how UMAP balances local versus global structure in the data.
478# See official documentation for details.
479n_neighbors = 15
480
481
482[reduce.tsne]
483# Placeholder for config values of tsne model
484
485
486[reduce.tsne.kwargs]
487# Specify any parameter accepted by https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html
488# Dimension of the embedded space
489n_components = 2
490
491# Number of nearest neighbors that is used in other manifold learning algorithms
492# See official documentation for details.
493perplexity = 30.0
494
495
496[reduce.pca]
497# Number of data points used to fit the pca model.
498fit_sample_size = 1024
499
500# Path to a pre-existing pca reducer model
501model_path = false
502
503
504[reduce.pca.kwargs]
505# Specify any parameter accepted by https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html#
506# Dimension of the embedded space
507n_components=2
508
509
510[visualize]
511
512# List of metadata field names to use in visualizer. Must be available as metadata in your dataset
513fields = []
514
515# Whether to display a panel of randomly chosen images corresponding to the selected points
516display_images = false
517
518# Name of catalog column to use for coloring points in the scatter plot. Use false for no coloring.
519color_column = false
520
521# Colormap to use for coloring points in the scatter plot when color_column is specified
522cmap = "viridis"
523
524# Only valid for .pt tensor images. Which bands should be loaded for display
525# [0,3,5] would map bands in that order to R,G,B. Single band will be grayscale.
526torch_tensor_bands = [3]
527
528# Whether to rasterize plot. Will break coloring (Haloviews Bug)
529# Helpful to reduce lag in large datasets.
530rasterize_plot = false
531
532
533[visualize_v2]
534
535# Number of hexagonal bins across the x-axis at any zoom level
536target_bins = 50
537
538# Extra padding around the viewport as a fraction of viewport width/height
539buffer_factor = 0.2
540
541# Plot dimensions in pixels
542plot_width = 1000
543plot_height = 1000
544
545# Colormap for hexbin density
546cmap = "Viridis"
547
548# Maximum rows rendered in the selection table
549max_table_rows = 1000
550
551# Number of detail plots per tab row
552num_detail_plots = 6
553
554
555
556[engine]
557
558# The directory containing the ONNX model used for inference in production
559model_directory = false
560
561
562[split]
563# Per-group split configuration. Keys correspond to groups in [data_request].
564# Values are a fraction of the group's primary dataset to use — (0.0, 1.0]
565# or a path to a previously generated <group>_split.npz file.
566# Groups absent from this table default to 1.0 (use the full dataset).
567
568# RNG seed for shuffling/partitioning. `false` uses config["data_set"]["seed"].
569# A non-empty value uses a dedicated generator and does affect global RNG state.
570rng_seed = false
571
572
573[balance]
574# Name of the field identifying each item's class. Must resolve to a
575# get_<field> getter on the primary dataset. `false` disables stratification.
576field = false
577
578# Data groups whose sampling weights are adjusted to the target distribution.
579# Empty list disables rebalancing. See [balance.distribution] for the target.
580groups = []
581
582[balance.distribution]
583# Maps class label → target fraction in (0.0, 1.0]. Empty table means equal
584# target across all observed classes (uniform). Values must sum to exactly 1.0.
585# Example:
586# cat = 0.25
587# dog = 0.75
588
589[label]
590# Optional. Maps human-readable string aliases to the raw values returned by
591# get_<balance.field>. Required when balance.distribution is used and
592# get_<balance.field> returns non-string values (e.g. integers),
593# All balance.distribution keys must appear here.
594# Example:
595# cat = 0
596# dog = 1
597# bird = 2