Description
When running guidellm benchmark run with --output-dir and --outputs json, the benchmark completes successfully but crashes during report serialization:
TypeError: Object of type PosixPath is not JSON serializable
Root Cause
In src/guidellm/benchmark/schemas/generative/report.py:105, save_file() calls:
model_dict = self.model_dump() # mode='python' (default)
save_str = json.dumps(model_dict) # TypeError
model_dump() defaults to mode='python', which preserves PosixPath objects. While BenchmarkGenerativeTextArgs has a @field_serializer("output_dir") that converts Path → str, that serializer only activates during model_dump_json() or model_dump(mode='json'), not the default model_dump().
The PosixPath originates from --output-dir, which click produces via click.Path(path_type=Path).
Reproduction
guidellm benchmark run \
--target "http://localhost:8000" \
--profile "kind=sweep" \
--data '{"kind": "json_file", "path": "sharegpt_flat.jsonl", "load_kwargs": {"split": "train"}}' \
--max-seconds 60 \
--max-requests 5000 \
--output-dir ./benchmark_results \
--outputs json,csv,html
Stack Trace
File "guidellm/benchmark/outputs/serialized.py", line 82, in finalize
return report.save_file(output_path)
File "guidellm/benchmark/schemas/generative/report.py", line 106, in save_file
save_str = json.dumps(model_dict)
File "json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
TypeError: Object of type PosixPath is not JSON serializable
Suggested Fix
Change report.py:105 to use JSON serialization mode:
model_dict = self.model_dump(mode='json')
This one-word change activates @field_serializer decorators and converts Path → str before json.dumps() sees it. The same fix should be applied to the YAML branch on line 108 as well.
Environment:
- guidellm version: latest (installed via pip)
- Python 3.12
- Linux
Description
When running
guidellm benchmark runwith--output-dirand--outputs json, the benchmark completes successfully but crashes during report serialization:Root Cause
In
src/guidellm/benchmark/schemas/generative/report.py:105,save_file()calls:model_dump()defaults tomode='python', which preservesPosixPathobjects. WhileBenchmarkGenerativeTextArgshas a@field_serializer("output_dir")that convertsPath → str, that serializer only activates duringmodel_dump_json()ormodel_dump(mode='json'), not the defaultmodel_dump().The
PosixPathoriginates from--output-dir, which click produces viaclick.Path(path_type=Path).Reproduction
Stack Trace
Suggested Fix
Change
report.py:105to use JSON serialization mode:This one-word change activates
@field_serializerdecorators and convertsPath → strbeforejson.dumps()sees it. The same fix should be applied to the YAML branch on line 108 as well.Environment: