Skip to main content

TrojAI provides the troj Python convenience package to allow users to integrate TrojAI adversarial protections and robustness metrics seamlessly into their AI development pipelines.

Project description

trojai-sdk

TrojAI's SDK and command line interface. This tool is used for submitting and monitoring jobs for evaluation by the TrojAI engine.

Uses

Command Line Functions

IMPORTANT: We've updated our authentication methods! Older auth configs required an id_token key and a refresh_token key. These keys are no longer required and should be removed from auth configs going forward. The only key required moving forward is the api_key.

The behaviour for submitting jobs using the command line is as follows:

Submit a valid config

tsdk -c path/to/config.json

The following arguments are intended to be used together to download failed results of a given job. Any feedback on this feature is appreciated!

Download failed samples from a given run

tsdk -dl_fails -job_name "trojeval-tabular-24052023-142652-850205" -auth_config ".\trojsdk\examples\auth_config_dev.json" -save_path "./failed_samples.json"

job_name: Can be found by using kubectl get pods. K8s creates the pods with an extra tag at the end, be sure to remove the randomly generated characters that prevent pod collisions.

Example: k8s pod name: trojeval-tabular-25052023-170036-121934-tknf5 valid job name: trojeval-tabular-25052023-170036-121934

Copy the job name of the evaluation when completed. You can also find the job name by clicking the Status column link in the front end project view for any run. auth_config: A path to a valid auth config for your cluster. Valid endpoint and api key are required save_path: where the resulting json file will be saved to

Programmatic Functions

We've added a more programmatic version of the config builder to be used in any python script. This TrojExperimenter is designed to be an aggregator for your trojai config files, and configs can be swapped in code instead of manually modifying json files.

A test example is detailed below:

conf_handler = TrojExperimenter("./trojsdk/examples/auth_config_dev.json")
proj = "test_proj"
dataset = "credit_dataset"
model = "logistic_model"
conf_handler.create_experiment(proj, dataset, model, delete_existing=True)
conf_handler.log_testing_data(path_to_dset_file="s3://trojai-object-storage/stars_tabular/stars_validation.csv", label_column="Type", classes_dictionary= {
    "red dwarf": 0,
    "brown dwarf": 1,
    "white dwarf":  2,
    "main sequence": 3,
    "super giants": 4,
    "hyper giants": 5
})
conf_handler.log_model(model = "s3://trojai-object-storage/stars_tabular/StarKNNPipe.pkl", model_wrapper_file = "s3://trojai-object-storage/stars_tabular/StarKNNWrapper.py")
conf_handler.log_attacks("./trojsdk/examples/star_attacks.json")
conf_handler.log_docker_metadata("trojai/troj-engine-base-tabular:tabular-dev-latest", "trojaicreds", "IfNotPresent")
k8s_dict = {
        "container_port": 80,
        "resources": {
            "requests": {
                "cpu": "250m",
                "memory": "800M"
            },
            "limits": {
                "cpu": "500m",
                "memory": "2000M"
            }
        },
        "tolerations": [
            {
                "effect": "NoSchedule",
                "operator": "Equal",
                "value": "robustness-evaluation",
                "key": "dedicated"
            }
        ]
    }
conf_handler.log_k8s_metadata(k8s_dict)
conf_handler.construct_base_config(task_type="tabular")
tjh = conf_handler.run_troj_evaluation(proj, dataset, model, no_ssl=True)

Config

For examples and explanations on creating valid your config files, please visit our gitbook.
Intro to TrojAI
NLP
Tabular

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

trojai-sdk-0.2.4.3.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

trojai_sdk-0.2.4.3-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file trojai-sdk-0.2.4.3.tar.gz.

File metadata

  • Download URL: trojai-sdk-0.2.4.3.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.5

File hashes

Hashes for trojai-sdk-0.2.4.3.tar.gz
Algorithm Hash digest
SHA256 8c592035d0795ab0205917d9f204efdbd8bdb232003535f44674d17f75158a24
MD5 86701bb6fd882b634fd6633c164009a6
BLAKE2b-256 5612646d9390ce4c280137660177ff3ebb406a8874ca08c0088d366ac881368d

See more details on using hashes here.

File details

Details for the file trojai_sdk-0.2.4.3-py3-none-any.whl.

File metadata

  • Download URL: trojai_sdk-0.2.4.3-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.5

File hashes

Hashes for trojai_sdk-0.2.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7e4199022b77f5ef8ae383ce346aae708b40b880e515939d1a7f5c20675a68e4
MD5 b5a5dcc665911cd614bc23df11b6e085
BLAKE2b-256 8ad96a63aa799546e0cf6ebc4eb2d281e0a96329142297cdef1f0684b6899caa

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