New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

irisml

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

irisml

Simple ML pipeline platform

  • 0.0.38
  • PyPI
  • Socket score

Maintainers
1

IrisML

Proof of Concept for a simple framework to create a ML pipeline.

Features

  • Run a ML training/inference with a simple JSON configuration.
  • Modularized interfaces for task components.
  • Cache task outputs for faster experiments.

Getting started

Installation

Prerequisite: python 3.8+

# Install the core framework and standard tasks.
pip install irisml irisml-tasks irisml-tasks-training

Run an example job

# Install additional packages that are required for the example
pip install irisml-tasks-torchvision

# Run on local machine
irisml_run docs/examples/mobilenetv2_mnist_training.json

Available commands

# Run the specified pipeline. You can provide environment variables by "-e" option, which will be acceible through $env variable in the json config.
irisml_run <pipeline_json_path> [-e <ENV_NAME>=<env_value>] [--no_cache] [--no_cache_read] [-v]

# Show information about the specified task. If <task_name> is not provided, shows a list of available tasks in the current environment.
irisml_show [<task_name>]

# Manage a cache storage on Azure Blob Storage
# list - Show a list of matched blobs.
# download - Download matched blobs.
# remove - Remove matched blobs.
# show - Show the contents of matched blobs.
irisml_cache <list|download|remove|show> [--mtime <+|->N] [--name NAME]

Pipeline definition

PipelineDefinition = {"tasks": List[TaskDefinition], "on_error": Optional[List[TaskDescription]]}

TaskDefinition = {
    "task": <task module name>,
    "name": <optional unique name of the task>,
    "inputs": <list of input objects>,
    "config": <config for the task. Use irisml_show command to find the available configurations.>
}

In the TaskDefinition.inputs and TaskDefinition.config, you cna use the following two variable.

  • $env.<variable_name> This variable will be replaced by the environment variable that was provided as arguments for irisml_run command.
  • $outputs.<task_name>.<field_name> This variable will be replaced by the outputs of the specified previous task.

It raises an exception on runtime if the specified variable was not found.

If a task raised an exception, the tasks specified in on_error field will be executed. The exception object will be assigned to "$env.IRISML_EXCEPTION" variable.

Patch definition (Experimental)

PatchesDefinition = {"patches": List[PatchDefinition], "patches_on_error": List[PatchDefinition]}  # At least one of the fields must be specified.

PatchDefinition = {  # One of the filtering conditions and one of the actions must be specified.
    # Filtering conditions
    "match": List[MatchCondition],
    "match_if_exists": List[MatchCondition],  # Matches the task if it exists. If not, the patch will be ignored.
    "match_oneof": List[MatchCondition],  # Matches the first task that matches one of the conditions.
    "top": bool,  # Matches the top of the pipeline. Used with "insert" action.
    "bottom": bool,  # Matches the bottom of the pipeline. Used with "insert" action.

    # Actions
    "insert": List[TaskDefinition],
    "remove": bool,
    "replace": Tuple[List[TaskDefinition], Dict[str, str]], # The second element is a mapping from the old output name to the new output name. All "$output" variables will be replaced by the new output name.
    "update": TaskDefinition
}

MatchCondition = {  # All fields are optional.
    "task": str,
    "name": str,
    "config": Dict[str, Any]
}

The available actions are as follows:

  • insert: Insert the specified tasks after the matched task.
  • remove: Remove the matched task.
  • replace: Replace the matched task with the specified tasks.
  • update: Update the matched task with the given configuration.

Note that the patch command doesn't guarantee the correctness of the patched pipeline. It is recommended to validate the patched pipeline.

Pipeline cache

Using cache, you can modify and re-run a pipeline config with minimum cost. If the cache is enabled, IrisML will calculate hash values for all task inputs/configs and upload the task outputs to a specified storage. When it found a task with same hash values, it can download the cache and skip the task execution.

To enable cache, you must specify the cache storage location by setting IRISML_CACHE_URL environment variable. Currently Azure Blob Storage and local filesystem is supported.

To use Azure Blob Storage, a container URL must be provided. It the URL contains a SAS token, it will be used for authentication. Otherwise, interactive authentication and Managed Identity authentication will be used.

Python API

To run a pipeline from python code, you can use the following APIs.

import json
import pathlib
from irisml.core import JobRunner

job_description = json.loads(pathlib.Path('example.json').read_text())
runner = JobRunner(job_description)

runner.run({'DATASET_NAME': 'mnist'})

runner.run({'DATASET_NAME': 'cifar10'})

Available official tasks

To show the detailed help for each task, run the following command after installing the package.

irisml_show <task_name>

irisml-tasks

TaskDescription
assertionAssert the given input.
assign_class_to_stringsAssigns a class to a string based on the class name being present in the string.
branch'If' conditional branch.
calculate_cosine_similarityCalculate cosine similarity between two sets of vectors.
check_model_parametersCheck Inf/NaN values in model parameters.
compareCompare two values
compare_intsCompare two int values.
convert_detection_to_multilabelConvert targets or predictions of object detection to multilabel.
convert_string_to_string_listConvert a string to a list of strings.
deserialize_tensorDeserialize a pytorch tensor.
divide_floatFloating point division.
download_azure_blobDownload a single blob from Azure Blob Storage.
emulate_fp8_quantizationEmulate FP8 quantization.
extract_image_bytes_from_datasetExtract images from a dataset and convert them to bytes.
get_current_timeGet the current time in seconds since the epoch
get_dataset_splitGet a train/val split of a dataset.
get_dataset_statsGet statistics of a dataset.
get_dataset_subsetGet a subset of a dataset.
get_fake_image_classification_datasetGenerate a fake image classification dataset.
get_fake_image_text_classification_datasetGenerate a fake image-text classification dataset.
get_fake_object_detection_datasetGenerate a fake object detection dataset.
get_fake_phrase_grounding_datasetGenerate a fake phrase grounding dataset.
get_fake_visual_question_answering_datasetGenerate a fake visual question answering dataset.
get_int_from_json_stringsGet an integer from a JSON string.
get_int_list_from_json_stringsGet a list of ints from a JSON string.
get_itemGet an item from the given list.
get_key_and_int_list_from_json_stringParse a JSON string and return a list of keys and a list of lists of ints.
get_kfold_cross_validation_datasetGet train/test dataset for k-fold cross validation.
get_secret_from_azure_keyvaultGet a secret from Azure KeyVault.
get_topkGet the largest Topk values and indices.
join_filepathJoin a given dir_path and a filename.
join_two_stringsJoin two strings to one string.
load_coco_detectionsLoad coco detections from a JSON to a list of tensors.
load_float_tensor_jsonlLoad a 2D float tensor from a JSONL file.
load_state_dictLoad a state_dict from various sources.
load_str_list_jsonlLoad a list of strings from a JSONL file.
load_strs_from_json_fileLoad strings from a JSON file.
load_tensor_listLoad a list of tensors from file.
make_cached_datasetSave dataset cache on disk.
make_prompt_for_each_stringMake a prompt for each string.
make_prompt_list_with_stringsMake a list of prompts from a template and a list of strings.
make_prompt_with_stringsMake a prompt with a list of strings.
make_random_choice_text_transformMake a text transform function that randomly chooses one of the substrings separated by the delimiter.
make_text_transformMake a text transform function.
map_int_listMap a list of integers to a list of integers.
pickling_objectPickling an object.
printPrint or Pretty Print the input object.
print_environment_infoPrint various environment information to stdout/stderr.
read_fileReads a file and returns its contents as bytes.
repeat_tasksRepeat the given tasks for multiple times.
run_parallelRun the given tasks in parallel. A new process will be forked for each task. Each task must have an unique name.
run_profilerRun profiler on the given tasks.
run_sequentialRun the given tasks in sequence. Each task must have an unique name.
save_fileSave the given input binary to a file.
save_float_tensor_jsonlSave a 2D float tensor to a JSONL file.
save_images_from_datasetSave images from a dataset to disk.
save_jit_modelSave an offline version of a pytorch model. torch.jit.save()
save_state_dictSave the model's state_dict to the specified file.
save_str_list_jsonlSave a list of strings to a JSONL file.
search_grid_sequentialGrid search hyperparameters. Tasks are run in sequence.
serialize_tensorSerialize a pytorch tensor.
split_stringSplit string to a list of strings.
switch_pickpick from vals based on conditions. Task will return the first val with condition being True.
upload_azure_blobUpload a binary file to Azure Storage Blob.
upload_azure_blob_directoryUpload a directory to Azure Blob Storage.

irisml-tasks-training

This package contains tasks related to pytorch training.

TaskDescription
append_classifierAppend a classifier model to a given model. A predictor and a loss module will be added, too.
benchmark_datasetBenchmark dataset loading and preprocessing
benchmark_modelBenchmark a given model using a given dataset.
benchmark_model_with_grad_cacheBenchmark a given model using a given dataset with grad caching. Useful for cases which require sub batching.
build_classification_prompt_datasetCreate a classification prompt dataset.
build_zero_shot_classifierCreate a zero-shot classification layer.
concatenate_datasetsConcatenate the given two datasets together.
convert_vqa_dataset_to_image_text_classification_datasetConvert VQA dataset to image text classification dataset.
create_classification_prompt_generatorCreate a prompt generator for a classification task.
create_prompt_generatorCreate a prompt generator that returns a list of prompts for a given label.
evaluate_accuracyCalculate accuracy of the given prediction results.
evaluate_captioningEvaluate captioning prediction results.
evaluate_detection_average_precisionCalculate mean average precision for object detection task results.
evaluate_phrase_groundingCalculate precision/recall for phrase grounding.
evaluate_phrase_grounding_recallCalculate recall for phrase grounding.
evaluate_string_matching_accuracyCalculate accuracy of string matching.
exclude_negative_samples_from_classification_datasetExclude negative samples from classification dataset.
export_coco_from_torch_datasetExport coco dataset from a given torch dataset. Support IC and OD only.
export_onnxExport the given model as ONNX.
extract_val_by_key_from_jsonlExtract value for each entry in a JSONL by a key.
find_incorrect_classification_indicesFind incorrect classification indices.
find_incorrect_classification_multilabel_indicesFind incorrect classification indices for multilabel classification.
flatten_captioning_datasetFlatten a captioning dataset with multiple targets per image into a dataset with a single target per image.
get_questions_from_vqa_datasetExtracts questions from a VQA dataset.
get_subclass_datasetGet the sub-dataset with given class ids from a dataset.
get_targets_from_datasetExtract only targets from a given Dataset.
load_jsonl_vqa_datasetLoad a VQA dataset from a jsonl file.
load_simple_classification_datasetLoad a simple classification dataset from a directory of images and an index file.
make_classification_dataset_from_object_detectionConvert an object detection dataset into a classification dataset.
make_classification_dataset_from_predictionsMake a classification dataset from predictions.
make_detection_dataset_from_predictionsMake a detection dataset from predictions.
make_feature_extractor_modelMake a wrapper model to extract a feature vector from a vision model.
make_fixed_prompt_image_transformMake a transform function for image and a fixed prompt.
make_fixed_text_datasetCreate a dataset with a list of strings.
make_image_text_contrastive_modelMake a model for image-text contrastive training.
make_image_text_transformMake a transform function for image-text classification.
make_oversampled_datasetMake an oversampled dataset.
make_phrase_grounding_image_transformMake phrase grounding image transform.
make_prompt_list_image_transformMake a transform function for image and prompt list.
make_vqa_collate_functionCreates a collate_function for Visual Question Answering (VQA) and Phrase Grounding task.
make_vqa_image_transformCreates a transform function for VQA task.
map_classification_predictions_to_detectionMap classification predictions back to detection predictions or targets.
num_iters_to_epochsConvert number of iterations to number of epochs. Min value is 1.
predictPredict using a given model.
remove_empty_images_from_datasetRemove empty images from dataset.
sample_few_shot_datasetFew-shot sampling of a IC/OD dataset.
save_jsonl_vqa_datasetSave a VQA dataset to a JSONL file.
split_image_text_modelSplit a image-text model into an image model and a text model.
trainTrain a pytorch model.
train_with_gradient_cacheTrain a model using gradient cache. Useful for contrastive learning with a large model.

irisml-tasks-azure-computervision

TaskDescription
create_azure_computervision_caption_modelCreate Azure Computer Vision Caption Model.
create_azure_computervision_classification_modelCreate Azure Computer Vision Caption Model.
create_azure_computervision_custom_modelCreate a model that run inference with a custom model in Azure Computer Vision.
create_azure_computervision_ocr_modelCreate Azure Computer Vision OCR model.
create_azure_computervision_product_recognizer_modelCreate a model that run inference with a product recognizer model in Azure Computer Vision.
create_azure_computervision_vectorization_modelCreate Azure Computer Vision Vectorization Model.
delete_azure_computervision_custom_modelDelete Azure Computer Vision Custom Model.
train_azure_computervision_custom_modelTrain Azure Computer Vision Custom Model.

irisml-tasks-azure-customvision

TaskDescription
create_azure_customvision_docker_modelCreate a model from an exported Azure Custom Vision Docker image.
create_azure_customvision_modelCreate a prediction model from an Azure Custom Vision project.
create_azure_customvision_projectCreate a new Azure Custom Vision project.
delete_azure_customvision_projectDelete an Azure Custom Vision project
export_azure_customvision_modelExport a model from an Azure Custom Vision project.
train_azure_customvision_projectTrain an Azure Custom Vision project.

irisml-tasks-azure-openai

TaskDescription
call_azure_openai_completionCall Azure OpenAI Text Completion API.
create_azure_openai_chat_modelCreate a model that generates text using Azure OpenAI completion API.
create_azure_openai_completion_modelCreate a model that generates text using Azure OpenAI completion API.

irisml-tasks-azureml

TaskDescription
run_azureml_childRun tasks as a new child AzureML Run.

irisml-tasks-fiftyone

TaskDescription
launch_fiftyoneLaunch a fiftyone app.

irisml-tasks-llava

TaskDescription
create_llava_modelCreate a LLaVA model from a pretrained weights.

irisml-tasks-onnx

Adapter tasks for OnnxRuntime library.

TaskDescription
benchmark_onnxBencharmk a given onnx model using onnxruntime.
predict_onnxPredict using a given onnx model traced with the export_onnx task

irisml-tasks-timm

Adapter for models in timm library.

TaskDescription
create_timm_modelCreate a timm model.
create_timm_transformCreate timm transforms.

irisml-tasks-torchmetrics

Adapter tasks for torchmetrics library.

TaskDescription
evaluate_torchmetrics_classification_multiclassEvaluate predictions results using torchmetrics classification metrics for multiclass classification problems.
evaluate_torchmetrics_classification_multilabelEvaluate predictions results using torchmetrics classification metrics for multilabel classification problems.

irisml-tasks-torchvision

Adapter tasks for torchvision library.

TaskDescription
create_torchvision_modelCreate a torchvision model.
create_torchvision_transformCreate transform objects in torchvision library.
create_torchvision_transform_v2Create torchvision transform v2 object from string expressions.
load_torchvision_datasetLoad a dataset from torchvision package.

irisml-tasks-transformers

Adapter tasks for HuggingFace transformers library.

TaskDescription
cache_transformers_model_on_azure_blobCache a model from transformers on Azure Blob Storage.
create_transformers_modelCreate a model using transformers library.
create_transformers_raw_tokenizerCreate a Tokenizer using transformers library. Return the tokenizer as-is.
create_transformers_text_modelCreate a text-generation model using transformers library.
create_transformers_tokenizerCreate a Tokenizer using transformers library.

Development

Create a new task

To create a Task, you must define a module that contains a "Task" class. Here is a simple example:

# irisml/tasks/my_custom_task.py
import dataclasses
import irisml.core

class Task(irisml.core.TaskBase):  # The class name must be "Task".
  VERSION = '1.0.0'
  CACHE_ENABLED = True  # (default: True) This is optional.

  @dataclasses.dataclass
  class Inputs:  # You can remove this class if the task doesn't require inputs.
    int_value: int
    float_value: float

  @dataclasses.dataclass
  class Config:  # If there is no configuration, you can remove this class. All fields must be JSON-serializable.
    another_float: float
    child_dataclass: dataclass  # If you'd like to define a nested config, you can define another dataclass.

  @dataclasses.dataclass
  class Outputs:  # Can be removed if the task doesn't have outputs.
    float_value: float = 0  # If dry_run() is not implemented, Outputs fields must have default value or default factory.

  def execute(self, inputs: Inputs) -> Outputs:
    return self.Outputs(inputs.int_value * inputs.float_value * self.config.another_float)

  def dry_run(self, inputs: Inputs) -> Outputs:  # This method is optional.
    return self.Outputs(0)  # Must return immediately without actual processing.

Each Task must define "execute" method. The base class has empty implementation for Inputs, Config, Outputs and dry_run(). For the detail, please see the document for TaskBase class.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc