gemini-code-assist[bot] commented on code in PR #18844:
URL: https://github.com/apache/tvm/pull/18844#discussion_r2867400747


##########
src/s_tir/meta_schedule/database/database.cc:
##########
@@ -43,7 +43,7 @@ Workload::Workload(IRModule mod, Workload::THashCode shash) {
 
 ObjectRef WorkloadNode::AsJSON() const {
   // Convert `this->mod` to JSON
-  std::string json_mod = tvm::SaveJSON(this->mod);
+  std::string json_mod = ffi::json::Stringify(ffi::ToJSONGraph(this->mod), 
/*indent=*/2);

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The previous `tvm::SaveJSON` function added `tvm_version` metadata to the 
serialized JSON. The new direct call to `ffi::ToJSONGraph` omits this. If the 
JSON representation of workloads is persisted in the database, this could cause 
issues with version compatibility. It would be safer to preserve the old 
behavior by adding the metadata back.
   
   ```suggestion
     std::string json_mod = ffi::json::Stringify(ffi::ToJSONGraph(this->mod, 
ffi::json::Object{{_TVM_STR_KEY, TVM_VERSION}}), /*indent=*/2);
   ```



##########
src/s_tir/meta_schedule/mutator/mutate_compute_location.cc:
##########
@@ -44,7 +44,8 @@ class MutateComputeLocationNode : public MutatorNode {
  public:
   // Inherit from `MutatorNode`
   void InitializeWithTuneContext(const TuneContext& context) final {
-    this->json_mod_ = SaveJSON(context->mod.value());
+    this->json_mod_ =
+        ffi::json::Stringify(ffi::ToJSONGraph(context->mod.value()), 
/*indent=*/2);

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The previous `SaveJSON` function added `tvm_version` metadata to the 
serialized JSON. The new direct call to `ffi::ToJSONGraph` omits this. This 
could cause issues with version compatibility if the JSON is persisted. It 
would be safer to preserve the old behavior by adding the metadata back.
   
   ```c
       this->json_mod_ = ffi::json::Stringify(
           ffi::ToJSONGraph(context->mod.value(), 
ffi::json::Object{{_TVM_STR_KEY, TVM_VERSION}}),
           /*indent=*/2);
   ```



##########
src/s_tir/meta_schedule/database/database_utils.cc:
##########
@@ -82,7 +82,7 @@ void JSONDumps(Any json_obj, std::ostringstream& os) {
     }
     os << "}";
   } else if (json_obj.as<tir::IndexMapNode>()) {
-    JSONDumps(ffi::String(SaveJSON(json_obj)), os);
+    JSONDumps(ffi::String(ffi::json::Stringify(ffi::ToJSONGraph(json_obj), 
/*indent=*/2)), os);

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The previous `SaveJSON` function added `tvm_version` metadata to the 
serialized JSON. The new direct call to `ffi::ToJSONGraph` omits this. To 
maintain version compatibility for persisted JSON, it's recommended to add the 
metadata back.
   
   ```suggestion
       JSONDumps(ffi::String(ffi::json::Stringify(ffi::ToJSONGraph(json_obj, 
ffi::json::Object{{_TVM_STR_KEY, TVM_VERSION}}), /*indent=*/2)), os);
   ```



##########
src/script/printer/utils.h:
##########
@@ -72,7 +73,10 @@ inline std::string Docsify(const ObjectRef& obj, const 
IRDocsifier& d, const Fra
     if (d->cfg->show_meta) {
       os << "metadata = tvm.ir.load_json(\"\"\""
          << support::StrEscape(
-                SaveJSON(ffi::Map<ffi::String, ffi::Any>(d->metadata.begin(), 
d->metadata.end())),
+                ffi::json::Stringify(
+                    ffi::ToJSONGraph(
+                        ffi::Map<ffi::String, ffi::Any>(d->metadata.begin(), 
d->metadata.end())),
+                    2),

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The previous `SaveJSON` function added `tvm_version` metadata to the 
serialized JSON. The new direct call to `ffi::ToJSONGraph` omits this. This 
could cause issues with version compatibility. It would be safer to preserve 
the old behavior by adding the metadata back.
   
   ```c
                   ffi::json::Stringify(
                       ffi::ToJSONGraph(
                           ffi::Map<ffi::String, ffi::Any>(d->metadata.begin(), 
d->metadata.end()),
                           ffi::json::Object{{_TVM_STR_KEY, TVM_VERSION}}),
                       2),
   ```



##########
src/s_tir/schedule/primitive/layout_transformation.cc:
##########
@@ -1656,14 +1658,16 @@ struct TransformBlockLayoutTraits : public 
UnpackedInstTraits<TransformBlockLayo
   static ObjectRef AttrsAsJSON(const ffi::Array<Any>& attrs) {
     ffi::Array<Any> attrs_record;
     attrs_record.reserve(kNumAttrs);
-    attrs_record.push_back(ffi::String(::tvm::SaveJSON(attrs[0])));
+    attrs_record.push_back(ffi::String(
+        ffi::json::Stringify(ffi::ToJSONGraph(attrs[0]), /*indent=*/2)));

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The previous `::tvm::SaveJSON` function added `tvm_version` metadata to the 
serialized JSON. The new direct call to `ffi::ToJSONGraph` omits this. To 
maintain version compatibility for persisted JSON, it's recommended to add the 
metadata back.
   
   ```suggestion
       attrs_record.push_back(ffi::String(ffi::json::Stringify(
           ffi::ToJSONGraph(attrs[0], ffi::json::Object{{_TVM_STR_KEY, 
TVM_VERSION}}),
           /*indent=*/2)));
   ```



##########
src/s_tir/meta_schedule/mutator/mutate_parallel.cc:
##########
@@ -189,7 +189,8 @@ class MutateParallelNode : public MutatorNode {
   void InitializeWithTuneContext(const TuneContext& context) final {
     Target target = context->target.value();
     this->max_parallel_extent_ = GetTargetNumCores(target) * 
this->max_jobs_per_core;
-    this->json_mod_ = SaveJSON(context->mod.value());
+    this->json_mod_ =
+        ffi::json::Stringify(ffi::ToJSONGraph(context->mod.value()), 
/*indent=*/2);

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The previous `SaveJSON` function added `tvm_version` metadata to the 
serialized JSON. The new direct call to `ffi::ToJSONGraph` omits this. This 
could cause issues with version compatibility if the JSON is persisted. It 
would be safer to preserve the old behavior by adding the metadata back.
   
   ```c
       this->json_mod_ = ffi::json::Stringify(
           ffi::ToJSONGraph(context->mod.value(), 
ffi::json::Object{{_TVM_STR_KEY, TVM_VERSION}}),
           /*indent=*/2);
   ```



##########
src/s_tir/schedule/primitive/layout_transformation.cc:
##########
@@ -1605,7 +1605,8 @@ struct TransformLayoutTraits : public 
UnpackedInstTraits<TransformLayoutTraits>
     attrs_record.push_back(attrs[0]);
     attrs_record.push_back(attrs[1]);
     if (attrs[2] != nullptr) {
-      attrs_record.push_back(ffi::String(::tvm::SaveJSON(attrs[2])));
+      attrs_record.push_back(ffi::String(
+          ffi::json::Stringify(ffi::ToJSONGraph(attrs[2]), /*indent=*/2)));

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The previous `::tvm::SaveJSON` function added `tvm_version` metadata to the 
serialized JSON. The new direct call to `ffi::ToJSONGraph` omits this. To 
maintain version compatibility for persisted JSON, it's recommended to add the 
metadata back.
   
   ```suggestion
         attrs_record.push_back(ffi::String(ffi::json::Stringify(
             ffi::ToJSONGraph(attrs[2], ffi::json::Object{{_TVM_STR_KEY, 
TVM_VERSION}}),
             /*indent=*/2)));
   ```



##########
src/s_tir/meta_schedule/mutator/mutate_thread_binding.cc:
##########
@@ -44,7 +44,8 @@ class MutateThreadBindingNode : public MutatorNode {
  public:
   // Inherit from `MutatorNode`
   void InitializeWithTuneContext(const TuneContext& context) final {
-    this->json_mod_ = SaveJSON(context->mod.value());
+    this->json_mod_ =
+        ffi::json::Stringify(ffi::ToJSONGraph(context->mod.value()), 
/*indent=*/2);

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The previous `SaveJSON` function added `tvm_version` metadata to the 
serialized JSON. The new direct call to `ffi::ToJSONGraph` omits this. This 
could cause issues with version compatibility if the JSON is persisted. It 
would be safer to preserve the old behavior by adding the metadata back.
   
   ```c
       this->json_mod_ = ffi::json::Stringify(
           ffi::ToJSONGraph(context->mod.value(), 
ffi::json::Object{{_TVM_STR_KEY, TVM_VERSION}}),
           /*indent=*/2);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to