ltsm.data_pipeline package

Submodules

ltsm.data_pipeline.anormly_pipeline module

Pipeline for Anormly Data Detection Main Difference from the LTSM :

  • pred_len == seq_len

  • label is the anomaly label of input seq_len

  • loss is CE/BCE

class ltsm.data_pipeline.anormly_pipeline.AnomalyTrainingPipeline(config, **kwargs)[source]

Bases: BaseTrainingPipeline

A pipeline for managing the training and evaluation process of a machine learning model.

args

Arguments containing training configuration and hyperparameters.

Type:

argparse.Namespace

model_manager

An instance responsible for creating, managing, and optimizing the model.

Type:

ModelManager

run()[source]

Runs the training and evaluation process for the model.

The process includes:
  • Logging configuration and training arguments.

  • Creating a model with the model manager.

  • Setting up training and evaluation parameters.

  • Loading and formatting training and evaluation datasets.

  • Training the model and saving metrics and state.

  • Evaluating the model on test datasets and logging metrics.

ltsm.data_pipeline.anormly_pipeline.anomaly_get_args()[source]
ltsm.data_pipeline.anormly_pipeline.anomaly_seed_all(fixed_seed)[source]
ltsm.data_pipeline.anormly_pipeline.compute_loss(model, inputs, return_outputs=False)[source]

Computes the loss for model training.

Parameters:
  • model (torch.nn.Module) – The model used for predictions.

  • inputs (dict) – Input data and labels.

  • return_outputs (bool) – If True, returns both loss and model outputs.

Returns:

The computed loss, and optionally the outputs.

Return type:

torch.Tensor or tuple

ltsm.data_pipeline.anormly_pipeline.compute_metrics(p)[source]

ltsm.data_pipeline.model_manager module

class ltsm.data_pipeline.model_manager.ModelManager(config)[source]

Bases: object

Manages model creation, parameter settings, optimizer, and evaluation metrics for training.

args

Configuration and hyperparameters for model training.

Type:

argparse.Namespace

model

The model to be trained, created based on configuration.

Type:

torch.nn.Module

optimizer

Optimizer for model parameter updates.

Type:

torch.optim.Optimizer

scheduler

Learning rate scheduler.

Type:

torch.optim.lr_scheduler._LRScheduler

collate_fn(batch)[source]

Collates a batch of data into tensors for model training.

Parameters:

batch (list) – List of data samples with ‘input_data’ and ‘labels’ keys.

Returns:

Collated batch with ‘input_data’ and ‘labels’ tensors.

Return type:

dict

compute_loss(model, inputs, return_outputs=False)[source]

Computes the loss for model training.

Parameters:
  • model (torch.nn.Module) – The model used for predictions.

  • inputs (dict) – Input data and labels.

  • return_outputs (bool) – If True, returns both loss and model outputs.

Returns:

The computed loss, and optionally the outputs.

Return type:

torch.Tensor or tuple

compute_metrics(p)[source]

Computes evaluation metrics for model predictions.

Parameters:

p (EvalPrediction) – Contains predictions and label IDs.

Returns:

Dictionary containing Mean Squared Error (MSE) and Mean Absolute Error (MAE).

Return type:

dict

create_model()[source]

Initializes and configures the model based on specified arguments, including options for freezing parameters or applying LoRA (Low-Rank Adaptation).

Returns:

The configured model ready for training.

Return type:

torch.nn.Module

prediction_step(model, inputs, prediction_loss_only=False, ignore_keys=None)[source]

Makes a prediction step, computing loss and returning model outputs without gradients.

Parameters:
  • model (torch.nn.Module) – The model used for predictions.

  • inputs (dict) – Input data and labels.

  • prediction_loss_only (bool) – If True, returns only the loss.

  • ignore_keys (list) – Keys to ignore in inputs.

Returns:

The loss, outputs, and labels.

Return type:

tuple

print_trainable_parameters()[source]

Prints the names of parameters in the model that are trainable.

set_optimizer()[source]

Configures the optimizer and learning rate scheduler for the model training.

Uses Adam optimizer and cosine annealing learning rate scheduler.

ltsm.data_pipeline.stat_pipeline module

class ltsm.data_pipeline.stat_pipeline.StatisticalTrainingPipeline(config, **kwargs)[source]

Bases: BaseTrainingPipeline

A pipeline for managing the training and evaluation process of a machine learning model.

args

Arguments containing training configuration and hyperparameters.

Type:

argparse.Namespace

model_manager

An instance responsible for creating, managing, and optimizing the model.

Type:

ModelManager

run()[source]

Runs the training and evaluation process for the model.

The process includes:
  • Logging config.train_params[“ration and training arguments.

  • Creating a model with the model manager.

  • Setting up training and evaluation parameters.

  • Loading and formatting training and evaluation datasets.

  • Training the model and saving metrics and state.

  • Evaluating the model on test datasets and logging metrics.

ltsm.data_pipeline.stat_pipeline.get_args()[source]
Return type:

TrainingConfig

ltsm.data_pipeline.stat_pipeline.seed_all(fixed_seed)[source]

ltsm.data_pipeline.tokenizer_pipeline module

Pipeline for tokenizer-ltsm. Task: Time Series Forecasting.

class ltsm.data_pipeline.tokenizer_pipeline.TokenizerTrainingPipeline(config, **kwargs)[source]

Bases: BaseTrainingPipeline

A pipeline for managing the training and evaluation process of a machine learning model.

args

Arguments containing training configuration and hyperparameters.

Type:

argparse.Namespace

model_manager

An instance responsible for creating, managing, and optimizing the model.

Type:

ModelManager

create_tokenizer()[source]

Creates a tokenizer for the model based on the configuration settings. The tokenizer is configured to handle input sequences, output sequences, and various parameters related to the model’s architecture and training process. :returns: An instance of the tokenizer configured for the model. :rtype: ChronosTokenizer

run()[source]

Runs the training and evaluation process for the model.

The process includes:
  • Logging configuration and training arguments.

  • Creating a model with the model manager.

  • Setting up training and evaluation parameters.

  • Loading and formatting training and evaluation datasets.

  • Training the model and saving metrics and state.

  • Evaluating the model on test datasets and logging metrics.

ltsm.data_pipeline.tokenizer_pipeline.tokenizer_get_args()[source]
ltsm.data_pipeline.tokenizer_pipeline.tokenizer_seed_all(fixed_seed)[source]

Module contents