Skip to content

Commit 09487af

Browse files
authored
[C++] Object declaration macro refactor (#3332)
This PR updates the object declaration macros, in order to follow the recent TVM refactor apache/tvm#18289.
1 parent 13a7d14 commit 09487af

File tree

17 files changed

+77
-74
lines changed

17 files changed

+77
-74
lines changed

3rdparty/tvm

Submodule tvm updated 213 files

cpp/serve/config.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,9 @@ class GenerationConfigNode : public Object {
135135

136136
picojson::object AsJSON() const;
137137

138-
static constexpr const char* _type_key = "mlc.serve.GenerationConfig";
139138
static constexpr const bool _type_has_method_sequal_reduce = false;
140139
static constexpr const bool _type_has_method_shash_reduce = false;
141-
TVM_DECLARE_BASE_OBJECT_INFO(GenerationConfigNode, Object);
140+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.GenerationConfig", GenerationConfigNode, Object);
142141
};
143142

144143
class GenerationConfig : public ObjectRef {
@@ -160,7 +159,7 @@ class GenerationConfig : public ObjectRef {
160159
/*! \brief Get the default generation config from the model config. */
161160
static GenerationConfig GetDefaultFromModelConfig(const picojson::object& json);
162161

163-
TVM_DEFINE_OBJECT_REF_METHODS(GenerationConfig, ObjectRef, GenerationConfigNode);
162+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(GenerationConfig, ObjectRef, GenerationConfigNode);
164163
};
165164

166165
/****************** Engine config ******************/
@@ -303,10 +302,10 @@ class EngineConfigNode : public Object {
303302

304303
String AsJSONString() const;
305304

306-
static constexpr const char* _type_key = "mlc.serve.EngineConfig";
307305
static constexpr const bool _type_has_method_sequal_reduce = false;
308306
static constexpr const bool _type_has_method_shash_reduce = false;
309-
TVM_DECLARE_BASE_OBJECT_INFO(EngineConfigNode, Object);
307+
static constexpr const bool _type_mutable = true;
308+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.EngineConfig", EngineConfigNode, Object);
310309
};
311310

312311
class EngineConfig : public ObjectRef {
@@ -322,7 +321,7 @@ class EngineConfig : public ObjectRef {
322321
static Result<std::vector<std::pair<std::string, std::string>>>
323322
GetModelsAndModelLibsFromJSONString(const std::string& json_str);
324323

325-
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(EngineConfig, ObjectRef, EngineConfigNode);
324+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(EngineConfig, ObjectRef, EngineConfigNode);
326325
};
327326

328327
/*! \brief A subset of engine config that is inferrable. */

cpp/serve/data.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ class DataNode : public Object {
5050
*/
5151
virtual ObjectRef GetEmbedding(Model model, ObjectRef* dst = nullptr, int offset = 0) const = 0;
5252

53-
static constexpr const char* _type_key = "mlc.serve.Data";
5453
static constexpr const bool _type_has_method_sequal_reduce = false;
5554
static constexpr const bool _type_has_method_shash_reduce = false;
56-
TVM_DECLARE_BASE_OBJECT_INFO(DataNode, Object);
55+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.Data", DataNode, Object);
5756
};
5857

5958
class Data : public ObjectRef {
6059
public:
61-
TVM_DEFINE_OBJECT_REF_METHODS(Data, ObjectRef, DataNode);
60+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Data, ObjectRef, DataNode);
6261
};
6362

6463
/*! \brief Split the given data array into two arrays at the "split_pos" position. */
@@ -76,15 +75,14 @@ class TextDataNode : public DataNode {
7675
int GetLength() const final;
7776
ObjectRef GetEmbedding(Model model, ObjectRef* dst = nullptr, int offset = 0) const final;
7877

79-
static constexpr const char* _type_key = "mlc.serve.TextData";
80-
TVM_DECLARE_BASE_OBJECT_INFO(TextDataNode, DataNode);
78+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.TextData", TextDataNode, DataNode);
8179
};
8280

8381
class TextData : public Data {
8482
public:
8583
explicit TextData(String text);
8684

87-
TVM_DEFINE_OBJECT_REF_METHODS(TextData, Data, TextDataNode);
85+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(TextData, Data, TextDataNode);
8886
};
8987

9088
/****************** TokenDataNode ******************/
@@ -98,8 +96,7 @@ class TokenDataNode : public DataNode {
9896
int GetLength() const final;
9997
ObjectRef GetEmbedding(Model model, ObjectRef* dst = nullptr, int offset = 0) const final;
10098

101-
static constexpr const char* _type_key = "mlc.serve.TokenData";
102-
TVM_DECLARE_BASE_OBJECT_INFO(TokenDataNode, DataNode);
99+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.TokenData", TokenDataNode, DataNode);
103100
};
104101

105102
class TokenData : public Data {
@@ -108,7 +105,7 @@ class TokenData : public Data {
108105

109106
explicit TokenData(std::vector<int32_t> token_ids);
110107

111-
TVM_DEFINE_OBJECT_REF_METHODS(TokenData, Data, TokenDataNode);
108+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(TokenData, Data, TokenDataNode);
112109
};
113110

114111
/****************** ImageDataNode ******************/
@@ -123,15 +120,14 @@ class ImageDataNode : public DataNode {
123120
int GetLength() const final;
124121
ObjectRef GetEmbedding(Model model, ObjectRef* dst = nullptr, int offset = 0) const final;
125122

126-
static constexpr const char* _type_key = "mlc.serve.ImageData";
127-
TVM_DECLARE_BASE_OBJECT_INFO(ImageDataNode, DataNode);
123+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.ImageData", ImageDataNode, DataNode);
128124
};
129125

130126
class ImageData : public Data {
131127
public:
132128
explicit ImageData(Tensor image, int embed_size);
133129

134-
TVM_DEFINE_OBJECT_REF_METHODS(ImageData, Data, ImageDataNode);
130+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ImageData, Data, ImageDataNode);
135131
};
136132

137133
/****************** SampleResult ******************/
@@ -201,10 +197,10 @@ class RequestStreamOutputObj : public Object {
201197

202198
std::atomic<bool> unpacked = false;
203199

204-
static constexpr const char* _type_key = "mlc.serve.RequestStreamOutput";
205200
static constexpr const bool _type_has_method_sequal_reduce = false;
206201
static constexpr const bool _type_has_method_shash_reduce = false;
207-
TVM_DECLARE_FINAL_OBJECT_INFO(RequestStreamOutputObj, Object);
202+
static constexpr const bool _type_mutable = true;
203+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.RequestStreamOutput", RequestStreamOutputObj, Object);
208204
};
209205

210206
/*!
@@ -221,7 +217,8 @@ class RequestStreamOutput : public ObjectRef {
221217

222218
static RequestStreamOutput Usage(String request_id, String request_final_usage_json_str);
223219

224-
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(RequestStreamOutput, ObjectRef, RequestStreamOutputObj);
220+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(RequestStreamOutput, ObjectRef,
221+
RequestStreamOutputObj);
225222
};
226223

227224
} // namespace serve

cpp/serve/draft_token_workspace_manager.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ class DraftTokenWorkspaceManagerObj : public Object {
7373
*/
7474
void FreeSlots(const std::vector<int>& slots);
7575

76-
static constexpr const char* _type_key = "mlc.serve.DraftTokenWorkspaceManager";
76+
static constexpr const bool _type_has_method_sequal_reduce = false;
77+
static constexpr const bool _type_has_method_shash_reduce = false;
78+
static constexpr const bool _type_mutable = true;
79+
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("mlc.serve.DraftTokenWorkspaceManager",
80+
DraftTokenWorkspaceManagerObj, Object);
7781

7882
private:
7983
std::vector<int> free_slots_;
@@ -94,8 +98,8 @@ class DraftTokenWorkspaceManager : public ObjectRef {
9498
data_ = tvm::ffi::make_object<DraftTokenWorkspaceManagerObj>(
9599
max_num_tokens, vocab_size, hidden_size, hidden_states_dtype, device, ft);
96100
}
97-
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(DraftTokenWorkspaceManager, ObjectRef,
98-
DraftTokenWorkspaceManagerObj);
101+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(DraftTokenWorkspaceManager, ObjectRef,
102+
DraftTokenWorkspaceManagerObj);
99103
};
100104

101105
} // namespace serve

cpp/serve/engine_actions/action.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class EngineActionObj : public Object {
3838
*/
3939
virtual Array<Request> Step(EngineState estate) = 0;
4040

41-
static constexpr const char* _type_key = "mlc.serve.EngineAction";
4241
static constexpr const bool _type_has_method_sequal_reduce = false;
4342
static constexpr const bool _type_has_method_shash_reduce = false;
44-
TVM_DECLARE_BASE_OBJECT_INFO(EngineActionObj, Object);
43+
static constexpr const bool _type_mutable = true;
44+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.EngineAction", EngineActionObj, Object);
4545
};
4646

4747
/*!
@@ -243,7 +243,7 @@ class EngineAction : public ObjectRef {
243243
std::vector<picojson::object> model_configs, Optional<EventTraceRecorder> trace_recorder,
244244
FRequestStreamCallback request_stream_callback, Device device);
245245

246-
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(EngineAction, ObjectRef, EngineActionObj);
246+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(EngineAction, ObjectRef, EngineActionObj);
247247
};
248248

249249
} // namespace serve

cpp/serve/engine_state.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ class EngineStateObj : public Object {
9898
/*! \brief Return the running request state entries*/
9999
const std::vector<RequestStateEntry>& GetRunningRequestStateEntries();
100100

101-
static constexpr const char* _type_key = "mlc.serve.EngineState";
102101
static constexpr const bool _type_has_method_sequal_reduce = false;
103102
static constexpr const bool _type_has_method_shash_reduce = false;
104-
TVM_DECLARE_FINAL_OBJECT_INFO(EngineStateObj, Object);
103+
static constexpr const bool _type_mutable = true;
104+
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("mlc.serve.EngineState", EngineStateObj, Object);
105105

106106
private:
107107
std::vector<RequestStateEntry> cached_running_rsentries_;
@@ -115,7 +115,7 @@ class EngineState : public ObjectRef {
115115
public:
116116
explicit EngineState();
117117

118-
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(EngineState, ObjectRef, EngineStateObj);
118+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(EngineState, ObjectRef, EngineStateObj);
119119
};
120120

121121
} // namespace serve

cpp/serve/event_trace_recorder.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ class EventTraceRecorderImpl : public EventTraceRecorderObj {
116116
return picojson::value(event_array).serialize();
117117
}
118118

119-
TVM_DECLARE_BASE_OBJECT_INFO(EventTraceRecorderImpl, EventTraceRecorderObj);
119+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.EventTraceRecorder", EventTraceRecorderImpl,
120+
EventTraceRecorderObj);
120121

121122
private:
122123
/*! \brief The internal impl of AddEvent, taking the event time as input. */

cpp/serve/event_trace_recorder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class EventTraceRecorderObj : public Object {
4141
/*! \brief Dump the logged events in Chrome Trace Event Format in JSON string. */
4242
virtual std::string DumpJSON() = 0;
4343

44-
static constexpr const char* _type_key = "mlc.serve.EventTraceRecorder";
4544
static constexpr const bool _type_has_method_sequal_reduce = false;
4645
static constexpr const bool _type_has_method_shash_reduce = false;
47-
TVM_DECLARE_BASE_OBJECT_INFO(EventTraceRecorderObj, Object);
46+
static constexpr const bool _type_mutable = true;
47+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.EventTraceRecorder", EventTraceRecorderObj, Object);
4848
};
4949

5050
/*!
@@ -56,7 +56,7 @@ class EventTraceRecorder : public ObjectRef {
5656
/*! \brief Create an event trace recorder. */
5757
static EventTraceRecorder Create();
5858

59-
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(EventTraceRecorder, ObjectRef, EventTraceRecorderObj);
59+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(EventTraceRecorder, ObjectRef, EventTraceRecorderObj);
6060
};
6161

6262
/****************** Helper macro ******************/

cpp/serve/logit_processor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ class LogitProcessorObj : public Object {
6868
const Array<String>& request_ids,
6969
const std::vector<int>* cum_num_token = nullptr) = 0;
7070

71-
static constexpr const char* _type_key = "mlc.serve.LogitProcessor";
7271
static constexpr const bool _type_has_method_sequal_reduce = false;
7372
static constexpr const bool _type_has_method_shash_reduce = false;
74-
TVM_DECLARE_BASE_OBJECT_INFO(LogitProcessorObj, Object);
73+
static constexpr const bool _type_mutable = true;
74+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.LogitProcessor", LogitProcessorObj, Object);
7575
};
7676

7777
class LogitProcessor : public ObjectRef {
@@ -87,7 +87,7 @@ class LogitProcessor : public ObjectRef {
8787
explicit LogitProcessor(int max_num_token, int vocab_size, FunctionTable* ft, DLDevice device,
8888
Optional<EventTraceRecorder> trace_recorder);
8989

90-
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(LogitProcessor, ObjectRef, LogitProcessorObj);
90+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(LogitProcessor, ObjectRef, LogitProcessorObj);
9191
};
9292

9393
} // namespace serve

cpp/serve/model.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ class ModelObj : public Object {
364364
/*! \brief Call the given global function on all workers. Only for debug purpose. */
365365
virtual void DebugCallFuncOnAllAllWorker(const String& func_name, Optional<String> func_args) = 0;
366366

367-
static constexpr const char* _type_key = "mlc.serve.Model";
368367
static constexpr const bool _type_has_method_sequal_reduce = false;
369368
static constexpr const bool _type_has_method_shash_reduce = false;
370-
TVM_DECLARE_BASE_OBJECT_INFO(ModelObj, Object);
369+
static constexpr const bool _type_mutable = true;
370+
TVM_FFI_DECLARE_OBJECT_INFO("mlc.serve.Model", ModelObj, Object);
371371
};
372372

373373
class Model : public ObjectRef {
@@ -396,7 +396,7 @@ class Model : public ObjectRef {
396396
*/
397397
static Result<picojson::object> LoadModelConfig(const String& model_path);
398398

399-
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(Model, ObjectRef, ModelObj);
399+
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Model, ObjectRef, ModelObj);
400400
};
401401

402402
} // namespace serve

0 commit comments

Comments
 (0)