Skip to content

Instantly share code, notes, and snippets.

@raghu-ramesha
Created February 14, 2023 00:04
Show Gist options
  • Save raghu-ramesha/784d8eb78f390bb2a512e7fc0a6e9e7a to your computer and use it in GitHub Desktop.
Save raghu-ramesha/784d8eb78f390bb2a512e7fc0a6e9e7a to your computer and use it in GitHub Desktop.
fil_backend_config
USE_GPU = True
FIL_MODEL_DIR = "./model_repository/fil"
# Maximum size in bytes for input and output arrays. If you are
# using Triton 21.11 or higher, all memory allocations will make
# use of Triton's memory pool, which has a default size of
# 67_108_864 bytes
MAX_MEMORY_BYTES = 60_000_000
NUM_FEATURES = 15
NUM_CLASSES = 2
bytes_per_sample = (NUM_FEATURES + NUM_CLASSES) * 4
max_batch_size = MAX_MEMORY_BYTES // bytes_per_sample
IS_CLASSIFIER = True
model_format = "xgboost_json"
# Select deployment hardware (GPU or CPU)
if USE_GPU:
instance_kind = "KIND_GPU"
else:
instance_kind = "KIND_CPU"
# whether the model is doing classification or regression
if IS_CLASSIFIER:
classifier_string = "true"
else:
classifier_string = "false"
# whether to predict probabilites or not
predict_proba = False
if predict_proba:
predict_proba_string = "true"
else:
predict_proba_string = "false"
config_text = f"""backend: "fil"
max_batch_size: {max_batch_size}
input [
{{
name: "input__0"
data_type: TYPE_FP32
dims: [ {NUM_FEATURES} ]
}}
]
output [
{{
name: "output__0"
data_type: TYPE_FP32
dims: [ 1 ]
}}
]
instance_group [{{ kind: {instance_kind} }}]
parameters [
{{
key: "model_type"
value: {{ string_value: "{model_format}" }}
}},
{{
key: "predict_proba"
value: {{ string_value: "{predict_proba_string}" }}
}},
{{
key: "output_class"
value: {{ string_value: "{classifier_string}" }}
}},
{{
key: "threshold"
value: {{ string_value: "0.5" }}
}},
{{
key: "storage_type"
value: {{ string_value: "AUTO" }}
}}
]
dynamic_batching {{}}"""
config_path = os.path.join(FIL_MODEL_DIR, "config.pbtxt")
with open(config_path, "w") as file_:
file_.write(config_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment