Skip to content

[Experiment] Python - Truncate suffix based on relevant context

Bruno Cardoso requested to merge exp-wrap-truncate-suffix-python-again into main

Redo of !305 (merged) as per !300 (comment 1510105955).

The description below is adapted from !305 (merged).


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.
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:

  1. Implement a new experiment by adding a new file under codesuggestions/experimentation/experiments/exp_<my_new_exp>.py
  2. Register this new experiment within _experiments_provider
  3. 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:

  1. Registration and running experiments
{"exp": "exp_truncate_suffix_python", "variants": 2, ... , "message": "registering experiment"}
{"exp": "exp_truncate_suffix_python", "variant": 0,  ... , "message": "running experiment"}
  1. 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"
}

Telemetry:

{
    "prompt_version": 1,
    "project_path": "string",
    "project_id": 0,
    "current_file":
    {
        "file_name": "app.py",
        "content_above_cursor": "def hello_world():",
        "content_below_cursor": ""
    },
    "telemetry":
    [
        {
            "model_engine": "vertex-ai",
            "model_name": "code-gecko",
            "lang": "python",
            "requests": 1,
            "accepts": 1,
            "errors": 0,
            "experiments":
            [
                {
                    "name": "exp_A",
                    "variant": "0"
                },
                {
                    "name": "exp_B",
                    "variant": "1"
                }
            ]
        }
    ]
}

On Prometheus:

code_suggestions_accepts_total{exp="exp_A,exp_B",exp_variant="0,1",lang="python",model_engine="vertex-ai",model_name="code-gecko"} 1.0

Follow-ups:

  • Add a private API to start/stop experiments and select a winning variant.
  • Isolation between experiments.
Edited by Bruno Cardoso

Merge request reports