[Experiment] Python - Truncate suffix based on relevant context
First iteration of https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/prompt-library/-/issues/10#note_1504408033.
This MR wraps !300 (merged) into an Experiment
by implementing the following:
- An
ExperimentRegistry
to keep track of all experiments. - An
Experiment
class supporting any number of variants each with its own probability of being selected. - A new counter to Prometheus.
# HELP code_suggestions_experiments_total Ongoing experiments
# TYPE code_suggestions_experiments_total counter
code_suggestions_experiments_total{name="exp_truncate_suffix_python",variant="0"} 5.0
code_suggestions_experiments_total{name="exp_truncate_suffix_python",variant="1"} 4.0
Proposed workflow:
- Implement a new experiment by adding a new file under
codesuggestions/experiments/exp_<my_new_exp>.py
- Register this new experiment within
ExperimentRegistry
- Run the experiment by forking the behaviour of the relevant code path:
if exp := experiment_registry.get_experiment("my_new_exp"):
exp.run(exp_args)
else:
# control
Logging:
- Registration and running experiments
{"exp": "exp_truncate_suffix_python", "variants": 2, ... , "message": "registering experiment"}
{"exp": "exp_truncate_suffix_python", "variant": 0, ... , "message": "running experiment"}
- Per request
Click to expand
{
"url": "http://localhost:5052/v2/completions",
"path": "/v2/completions",
"status_code": 200,
"method": "POST",
"correlation_id": "cb7bd7047d2540cea5a6a8cf73d6d51b",
"http_version": "1.1",
"client_ip": "127.0.0.1",
"client_port": 52470,
"duration_s": 6.628565332999999,
"cpu_s": 0.5642009999999997,
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
"model_engine": "vertex-ai",
"model_name": "code-gecko",
"prompt_length": 81,
"prompt_length_stripped": 67,
"inference_duration_s": 6.13059125,
"suffix_length": 0,
"prompt_symbols":
{
"comment": 1,
"function_definition": 1
},
"experiments":
[
{
"exp": "exp_truncate_suffix_python",
"exp_variant": 0
}
],
"model_output_length": 91,
"model_output_length_stripped": 70,
"logger": "api.access",
"level": "info",
"type": "mlops",
"stage": "main",
"timestamp": "2023-08-09T11:55:53.495457Z",
"message": "127.0.0.1:52470 - \"POST /v2/completions HTTP/1.1\" 200"
}
Follow-ups:
- Add a private API to start/stop experiments and select a winning variant.
- Isolation between experiments.
Edited by Bruno Cardoso