Skip to content

refactor: Remove picojson dependency, replace with tvm::ffi::json API#3423

Draft
MasterJH5574 wants to merge 1 commit intomlc-ai:mainfrom
MasterJH5574:02-11-json
Draft

refactor: Remove picojson dependency, replace with tvm::ffi::json API#3423
MasterJH5574 wants to merge 1 commit intomlc-ai:mainfrom
MasterJH5574:02-11-json

Conversation

@MasterJH5574
Copy link
Member

Migrate all picojson usages to the new tvm::ffi::json API built on the FFI type system.

@gemini-code-assist
Copy link

Summary of Changes

Hello @MasterJH5574, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request executes a substantial refactoring to unify JSON operations across the project. It replaces the picojson library with the tvm::ffi::json API, which is integrated with the FFI type system. This change affects build configurations, core data structures, and utility functions responsible for JSON parsing and serialization, leading to a more cohesive and robust JSON handling infrastructure.

Highlights

  • Dependency Removal: The external picojson library has been completely removed from the codebase, streamlining dependencies.
  • API Migration: All instances of picojson usage have been migrated to the new tvm::ffi::json API, which is built on the FFI type system for consistent JSON handling.
  • Build System Updates: CMake configuration files were updated to remove picojson includes and compile definitions, while also ensuring xgrammar's bundled picojson dependency is correctly managed.
  • JSON Handling Refactor: Core JSON parsing, lookup, and serialization logic across various C++ files have been updated to utilize tvm::ffi::json::Object, tvm::ffi::json::Array, and tvm::ffi::json::Value types, enhancing type safety and consistency.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • CMakeLists.txt
    • Removed picojson include and compile definitions
    • Added xgrammar's bundled picojson include for its dependency
  • android/mlc4j/CMakeLists.txt
    • Removed picojson include from Android build configuration
  • cpp/json_ffi/conv_template.cc
    • Updated FromJSON methods for ModelVisionConfig and Conversation to use tvm::ffi::json::Object and Array
    • Adjusted type casting for JSON values
  • cpp/json_ffi/conv_template.h
    • Updated FromJSON method signatures to use tvm::ffi::json::Object
  • cpp/json_ffi/json_ffi_engine.cc
    • Replaced picojson includes with tvm/ffi/extra/json.h
    • Updated JSON array/object creation and serialization for stream responses and model config loading
  • cpp/json_ffi/openai_api_protocol.cc
    • Updated FromJSON and AsJSON methods for various OpenAI API protocol structs to use tvm::ffi::json types and methods
  • cpp/json_ffi/openai_api_protocol.h
    • Updated method signatures for JSON parsing and serialization to use tvm::ffi::json types
  • cpp/metadata/model.cc
    • Updated FromJSON methods for model metadata structures to use tvm::ffi::json::Object and Array
    • Adjusted type casting for JSON values
  • cpp/metadata/model.h
    • Replaced picojson.h include with tvm/ffi/extra/json.h
    • Updated method signatures for model metadata JSON handling
  • cpp/multi_gpu/multi_gpu_loader.cc
    • Replaced picojson.h include with tvm/ffi/extra/json.h
    • Updated JSON parsing for model configuration during multi-GPU loading
  • cpp/serve/config.cc
    • Removed picojson.h include
    • Updated FromJSON and AsJSON methods for configuration structures (ResponseFormat, DisaggConfig, DebugConfig, GenerationConfig) to use tvm::ffi::json types
    • Updated EngineConfig JSON parsing and serialization logic
  • cpp/serve/config.h
    • Replaced picojson.h include with tvm/ffi/extra/json.h
    • Updated method signatures for configuration JSON handling
  • cpp/serve/engine.cc
    • Updated GetTokenizerInfo and Create methods to use tvm::ffi::json::Object for model configurations
    • Updated JSON metrics serialization
  • cpp/serve/engine_actions/action.h
    • Updated function signatures to use std::vector<tvm::ffi::json::Object> for model configurations
  • cpp/serve/engine_actions/action_commons.cc
    • Updated function signature to use std::vector<tvm::ffi::json::Object> for model configurations
  • cpp/serve/engine_actions/action_commons.h
    • Updated function signature to use std::vector<tvm::ffi::json::Object> for model configurations
  • cpp/serve/engine_actions/batch_prefill_base.cc
    • Updated constructor to use std::vector<tvm::ffi::json::Object> for model configurations
  • cpp/serve/engine_actions/batch_prefill_base.h
    • Updated constructor signature to use std::vector<tvm::ffi::json::Object>
  • cpp/serve/engine_actions/disagg_prepare_recv.cc
    • Updated constructor to use tvm::ffi::json::Object for model configurations
    • Updated JSON serialization for response body and usage
  • cpp/serve/engine_actions/disagg_remote_send.cc
    • Updated constructor signature to use tvm::ffi::json::Object for model configurations
  • cpp/serve/engine_actions/eagle_new_request_prefill.cc
    • Updated constructor signature to use tvm::ffi::json::Object for model configurations
  • cpp/serve/engine_actions/new_request_prefill.cc
    • Updated constructor signature to use tvm::ffi::json::Object for model configurations
  • cpp/serve/engine_state.h
    • Removed picojson.h include
  • cpp/serve/event_trace_recorder.cc
    • Replaced picojson.h include with tvm/ffi/extra/json.h
    • Updated JSON serialization for event tracing
  • cpp/serve/function_table.cc
    • Updated Init method and LoadParams to use tvm::ffi::json::Object and tvm::ffi::json::Stringify
  • cpp/serve/function_table.h
    • Replaced picojson.h include with tvm/ffi/extra/json.h
    • Updated Init method signature and model_config member type to tvm::ffi::json::Object
  • cpp/serve/logit_processor.cc
    • Removed picojson.h include
  • cpp/serve/metrics.cc
    • Updated AsJSON methods for TimeCost, SpecDecodeMetrics, RequestMetrics, and EngineMetrics to use tvm::ffi::json types and methods
  • cpp/serve/metrics.h
    • Replaced picojson.h include with tvm/ffi/extra/json.h
    • Updated method signatures for metrics JSON handling
  • cpp/serve/model.cc
    • Updated Create and LoadModelConfig methods to use tvm::ffi::json::Object and tvm::ffi::json::Parse
  • cpp/serve/model.h
    • Replaced picojson.h include with tvm/ffi/extra/json.h
    • Updated method signatures for model JSON handling
  • cpp/serve/request.cc
    • Updated RequestGetGenerationConfigJSON to use tvm::ffi::json::Stringify
  • cpp/serve/threaded_engine.cc
    • Updated CreateRequest to use json::Object for parsing generation configuration
  • cpp/serve/threaded_engine.h
    • Removed picojson.h include
  • cpp/support/json_parser.h
    • Replaced picojson types with tvm::ffi::json types (Object, Array, Value) in all JSON utility functions
    • Updated ParseToJSONObject, Lookup, LookupOrDefault, LookupOptional, LookupWithResultReturn, LookupOrDefaultWithResultReturn, LookupOptionalWithResultReturn, and SymShapeTuple conversion logic
  • cpp/tokenizers/tokenizers.cc
    • Replaced picojson.h include with tvm/ffi/extra/json.h
    • Updated AsJSONString and FromJSONString methods for TokenizerInfoNode to use tvm::ffi::json types and methods
    • Updated DetectTokenizerInfo to use tvm::ffi::json for parsing tokenizer configuration
Activity
  • The author, MasterJH5574, initiated a comprehensive refactoring to replace the picojson dependency.
  • Numerous code changes were implemented across various C++ files to adapt to the new tvm::ffi::json API.
  • Build system files were modified to reflect the updated JSON library usage.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@MasterJH5574
Copy link
Member Author

Mark as draft since it still depends on a tvm-ffi fix apache/tvm-ffi#442. We won't be able to get this PR in before a new version of tvm-ffi is released.

@MasterJH5574 MasterJH5574 marked this pull request as draft February 12, 2026 02:56
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a large-scale refactoring to replace the picojson dependency with the tvm::ffi::json API. The changes are extensive and appear to be correctly implemented across the codebase, consistently applying the new API for JSON manipulation. The migration is well-executed, improving dependency management. I've found a minor inconsistency in how JSON arrays are iterated in one file and have provided suggestions to align it with the rest of the codebase for better maintainability.

Migrate all picojson usages to the new tvm::ffi::json API built on the
FFI type system.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant