Skip to main content

Utilities for ML models targeting hardware triggers

Project description

Machine Learning for Hardware Triggers

triggerflow provides a set of utilities for Machine Learning models targeting FPGA deployment. The TriggerModel class consolidates several Machine Learning frontends and compiler backends to construct a "trigger model". MLflow utilities are for logging, versioning, and loading of trigger models.

Installation

pip install triggerflow

Usage

from triggerflow.core import TriggerModel


scales = {'offsets': np.array([18, 0, 72, 7, 0, 73, 4, 0, 73, 4, 0, 72, 3, 0, 72, 6, -0, 286, 3, -2, 285, 3, -2, 282, 3, -2, 286, 29, 0, 72, 22, 0, 72, 18, 0, 72, 14, 0, 72, 11, 0, 72, 10, 0, 72, 10, 0, 73, 9, 0], dtype='int'),
'shifts': np.array([3, 0, 6, 2, 5, 6, 0, 5, 6, 0, 5, 6, -1, 5, 6, 2, 7, 8, 0, 7, 8, 0, 7, 8, 0, 7, 8, 4, 6, 6, 3, 6, 6, 3, 6, 6, 3, 6, 6, 3, 6, 6, 3, 6, 6, 3, 6, 6, 3, 6], dtype='int')}


trigger_model = TriggerModel(
    config="triggermodel_config.yaml",
    native_model=model, #Native XGboost/Keras model
    scales=scales
)

trigger_model() #Vivado requird on $PATH for Firmware build.

# then:
output_software = trigger_model.software_predict(input_data)
output_firmware = trigger_model.firmware_predict(input_data)
output_qonnx = trigger_model.qonnx_predict(input_data)

# save and load trigger models:
trigger_model.save("triggerflow.tar.xz")

# in a separate session:
from triggerflow.core import TriggerModel
triggerflow = TriggerModel.load("triggerflow.tar.xz")

The Config file:

Use this .yaml template and change as needed.

compiler:
  name: "AXO"
  ml_backend: "keras"
  compiler: "hls4ml"
  fpga_part: "xc7vx690t-ffg1927-2"
  clock_period: 25
  n_outputs: 1
  project_name: "AXO_project"
  namespace: "AXO"
  io_type: "io_parallel"
  backend: "Vitis"
  write_weights_txt: false

subsystem:
  name: "uGT"
  n_inputs: 50
  offset_type: "ap_fixed<10,10>"
  shift_type: "ap_fixed<10,10>"

  objects:
    muons:
      size: 4
      features: [pt, eta_extrapolated, phi_extrapolated]

    jets:
      size: 4
      features: [et, eta, phi]

    egammas:
      size: 4
      features: [et, eta, phi]

    taus:
      size: 4
      features: [et, eta, phi]

  global_features:
    #- et.et
    #- ht.et
    - etmiss.et
    - etmiss.phi
    #- htmiss.et
    #- htmiss.phi
    #- ethfmiss.et
    #- ethfmiss.phi
    #- hthfmiss.et
    #- hthfmiss.phi

  muon_size: 4
  jet_size: 4
  egamma_size: 4
  tau_size: 4

Logging with MLflow

# logging with MLFlow:
import mlflow
from triggerflow.mlflow_wrapper import log_model

mlflow.set_tracking_uri("https://ngt.cern.ch/models")
experiment_id = mlflow.create_experiment("example-experiment")

with mlflow.start_run(run_name="trial-v1", experiment_id=experiment_id):
    log_model(triggerflow, registered_model_name="TriggerModel")

Note: This package doesn't install dependencies so it won't disrupt specific training environments or custom compilers. For a reference environment, see environment.yml.

Creating a kedro pipeline

This repository also comes with a default pipeline for trigger models based on kedro. One can create a new pipeline via:

NOTE: no "-" and upper cases!

# Create a conda environment & activate it
conda create -n triggerflow python=3.11
conda activate triggerflow

# install triggerflow
pip install triggerflow

# Create a pipeline
triggerflow new demo_pipeline

# NOTE: since we dont install dependency one has to create a
# conda env based on the environment.yml file of the pipeline
# this file can be changed to the needs of the indiviual project
cd demo_pipeline
conda env update -n triggerflow --file environment.yml

# Run Kedro
kedro run

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

triggerflow-0.3.7.tar.gz (11.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

triggerflow-0.3.7-py3-none-any.whl (11.1 MB view details)

Uploaded Python 3

File details

Details for the file triggerflow-0.3.7.tar.gz.

File metadata

  • Download URL: triggerflow-0.3.7.tar.gz
  • Upload date:
  • Size: 11.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for triggerflow-0.3.7.tar.gz
Algorithm Hash digest
SHA256 596c5bb2bc93902143351d0c273af24c11a4000a5bd20702fec3025df4a1a710
MD5 68905317b14335ae49eeb4530fe4f8c3
BLAKE2b-256 3090fd36daf5074a4e3bd171777aa00c85ef3ff0418e2c0b9d0053d8b1c6cdba

See more details on using hashes here.

File details

Details for the file triggerflow-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: triggerflow-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 11.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for triggerflow-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0ad84eaf05f0d5f42a65005610af728ea9e6812a795ceb32f3bef5075bffb84a
MD5 1d1eaaf9c8ac546f01fc8dbe1dd756e7
BLAKE2b-256 427b2e9a90977e41df05899d0bb1d1364cd3ff1307244a3aa0de6c517e09b3f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page