Skip to content

Commit c51f083

Browse files
authored
[FFI] Namespace cleanup (#3329)
Following apache/tvm#18280, this PR updates the ffi namespace in MLC.
1 parent 91d95f9 commit c51f083

27 files changed

+50
-47
lines changed

3rdparty/tvm

Submodule tvm updated 912 files

cpp/json_ffi/json_ffi_engine.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool JSONFFIEngine::AddRequest(std::string request_json_str, std::string request
9898
}
9999
// create a generation config from request
100100
const auto& default_gen_cfg = default_generation_config_;
101-
auto gen_cfg = make_object<GenerationConfigNode>();
101+
auto gen_cfg = tvm::ffi::make_object<GenerationConfigNode>();
102102
gen_cfg->n = request.n;
103103
gen_cfg->temperature = request.temperature.value_or(default_gen_cfg->temperature);
104104
gen_cfg->top_p = request.top_p.value_or(default_gen_cfg->top_p);
@@ -299,7 +299,7 @@ class JSONFFIEngineImpl : public JSONFFIEngine, public ffi::ModuleObj {
299299
TVM_FFI_STATIC_INIT_BLOCK({
300300
namespace refl = tvm::ffi::reflection;
301301
refl::GlobalDef().def("mlc.json_ffi.CreateJSONFFIEngine",
302-
[]() { return ffi::Module(make_object<JSONFFIEngineImpl>()); });
302+
[]() { return ffi::Module(tvm::ffi::make_object<JSONFFIEngineImpl>()); });
303303
});
304304

305305
} // namespace json_ffi

cpp/serve/config.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Result<GenerationConfig> GenerationConfig::Validate(GenerationConfig cfg) {
264264
Result<GenerationConfig> GenerationConfig::FromJSON(const picojson::object& config,
265265
const GenerationConfig& default_config) {
266266
using TResult = Result<GenerationConfig>;
267-
ObjectPtr<GenerationConfigNode> n = make_object<GenerationConfigNode>();
267+
ObjectPtr<GenerationConfigNode> n = tvm::ffi::make_object<GenerationConfigNode>();
268268
n->n = json::LookupOrDefault<int64_t>(config, "n", default_config->n);
269269
n->temperature =
270270
json::LookupOrDefault<double>(config, "temperature", default_config->temperature);
@@ -358,7 +358,7 @@ Result<GenerationConfig> GenerationConfig::FromJSON(const picojson::object& conf
358358

359359
GenerationConfig GenerationConfig::GetDefaultFromModelConfig(
360360
const picojson::object& model_config_json) {
361-
ObjectPtr<GenerationConfigNode> n = make_object<GenerationConfigNode>();
361+
ObjectPtr<GenerationConfigNode> n = tvm::ffi::make_object<GenerationConfigNode>();
362362
n->max_tokens = -1;
363363
n->temperature = json::LookupOrDefault<double>(model_config_json, "temperature", n->temperature);
364364
n->top_p = json::LookupOrDefault<double>(model_config_json, "top_p", n->top_p);
@@ -418,7 +418,7 @@ EngineConfig EngineConfig::FromJSONAndInferredConfig(
418418
CHECK(inferred_config.max_total_sequence_length.has_value());
419419
CHECK(inferred_config.prefill_chunk_size.has_value());
420420
CHECK(inferred_config.max_history_size.has_value());
421-
ObjectPtr<EngineConfigNode> n = make_object<EngineConfigNode>();
421+
ObjectPtr<EngineConfigNode> n = tvm::ffi::make_object<EngineConfigNode>();
422422

423423
// - Get models and model libs.
424424
n->model = json::Lookup<std::string>(json, "model");

cpp/serve/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace serve {
2323

2424
using namespace tvm;
2525
using namespace tvm::runtime;
26+
using tvm::ffi::Array;
27+
using tvm::ffi::Optional;
28+
using tvm::ffi::String;
2629

2730
/****************** GenerationConfig ******************/
2831

cpp/serve/data.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ std::pair<Array<Data>, Array<Data>> SplitData(const Array<Data>& original_data,
5757
/****************** TextData ******************/
5858

5959
TextData::TextData(String text) {
60-
ObjectPtr<TextDataNode> n = make_object<TextDataNode>();
60+
ObjectPtr<TextDataNode> n = tvm::ffi::make_object<TextDataNode>();
6161
n->text = std::move(text);
6262
data_ = std::move(n);
6363
}
@@ -82,13 +82,13 @@ TVM_FFI_STATIC_INIT_BLOCK({
8282
/****************** TokenData ******************/
8383

8484
TokenData::TokenData(IntTuple token_ids) {
85-
ObjectPtr<TokenDataNode> n = make_object<TokenDataNode>();
85+
ObjectPtr<TokenDataNode> n = tvm::ffi::make_object<TokenDataNode>();
8686
n->token_ids = std::move(token_ids);
8787
data_ = std::move(n);
8888
}
8989

9090
TokenData::TokenData(std::vector<int32_t> token_ids) {
91-
ObjectPtr<TokenDataNode> n = make_object<TokenDataNode>();
91+
ObjectPtr<TokenDataNode> n = tvm::ffi::make_object<TokenDataNode>();
9292
n->token_ids = IntTuple(token_ids.begin(), token_ids.end());
9393
data_ = std::move(n);
9494
}
@@ -117,7 +117,7 @@ TVM_FFI_STATIC_INIT_BLOCK({
117117
/****************** ImageData ******************/
118118

119119
ImageData::ImageData(Tensor image, int embed_size) {
120-
ObjectPtr<ImageDataNode> n = make_object<ImageDataNode>();
120+
ObjectPtr<ImageDataNode> n = tvm::ffi::make_object<ImageDataNode>();
121121
n->image = std::move(image);
122122
n->embed_size = embed_size;
123123
data_ = std::move(n);
@@ -206,7 +206,7 @@ RequestStreamOutput::RequestStreamOutput(
206206
std::optional<std::vector<std::vector<String>>> group_delta_logprob_json_strs,
207207
std::vector<Optional<String>> group_finish_reason,
208208
std::vector<String> group_extra_prefix_string) {
209-
ObjectPtr<RequestStreamOutputObj> n = make_object<RequestStreamOutputObj>();
209+
ObjectPtr<RequestStreamOutputObj> n = tvm::ffi::make_object<RequestStreamOutputObj>();
210210
n->request_id = std::move(request_id);
211211
n->group_delta_token_ids = std::move(group_delta_token_ids);
212212
n->group_delta_logprob_json_strs = std::move(group_delta_logprob_json_strs);
@@ -217,7 +217,7 @@ RequestStreamOutput::RequestStreamOutput(
217217

218218
RequestStreamOutput RequestStreamOutput::Usage(String request_id,
219219
String request_final_usage_json_str) {
220-
ObjectPtr<RequestStreamOutputObj> n = make_object<RequestStreamOutputObj>();
220+
ObjectPtr<RequestStreamOutputObj> n = tvm::ffi::make_object<RequestStreamOutputObj>();
221221
n->request_id = std::move(request_id);
222222
n->request_final_usage_json_str = std::move(request_final_usage_json_str);
223223
return RequestStreamOutput(n);

cpp/serve/engine.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ inline std::optional<TokenizerInfo> GetTokenizerInfo(const picojson::object& mod
5555
}
5656
const picojson::object& tokenizer_info_obj =
5757
model_config.at("tokenizer_info").get<picojson::object>();
58-
auto info = make_object<TokenizerInfoNode>();
58+
auto info = tvm::ffi::make_object<TokenizerInfoNode>();
5959
if (tokenizer_info_obj.count("token_postproc_method")) {
6060
info->token_postproc_method = tokenizer_info_obj.at("token_postproc_method").get<std::string>();
6161
}
@@ -583,7 +583,7 @@ class EngineImpl : public Engine {
583583
}
584584
// - Override the "n" in generation config to 1.
585585
ObjectPtr<GenerationConfigNode> updated_generation_cfg =
586-
make_object<GenerationConfigNode>(*request->generation_cfg.get());
586+
tvm::ffi::make_object<GenerationConfigNode>(*request->generation_cfg.get());
587587
updated_generation_cfg->n = 1;
588588
request->generation_cfg = GenerationConfig(updated_generation_cfg);
589589
return false;
@@ -617,7 +617,7 @@ class EngineImpl : public Engine {
617617

618618
RequestState rstate = it_rstate->second;
619619
ObjectPtr<GenerationConfigNode> updated_generation_cfg =
620-
make_object<GenerationConfigNode>(*request->generation_cfg.get());
620+
tvm::ffi::make_object<GenerationConfigNode>(*request->generation_cfg.get());
621621
// - Split the input data into two parts at the position "kv_window_begin".
622622
CHECK(!request->inputs.empty());
623623
auto [lhs_data, rhs_data] = SplitData(request->inputs, input_length, kv_window_begin);
@@ -895,7 +895,7 @@ class EngineImpl : public Engine {
895895
return TResult::Error(err);
896896
}
897897
picojson::object config = config_json.get<picojson::object>();
898-
ObjectPtr<EngineConfigNode> n = make_object<EngineConfigNode>();
898+
ObjectPtr<EngineConfigNode> n = tvm::ffi::make_object<EngineConfigNode>();
899899

900900
// - Get the engine mode and maximum GPU utilization for inference.
901901
EngineMode mode = EngineModeFromString(json::Lookup<std::string>(config, "mode"));
@@ -1049,7 +1049,7 @@ class EngineModule : public ffi::ModuleObj {
10491049
this->default_generation_config_ = output.default_generation_cfg;
10501050
}
10511051
/*! \brief Construct an EngineModule. */
1052-
static ffi::Module Create() { return ffi::Module(make_object<EngineModule>()); }
1052+
static ffi::Module Create() { return ffi::Module(tvm::ffi::make_object<EngineModule>()); }
10531053
/*! \brief Redirection to `Engine::AddRequest`. */
10541054
void AddRequest(Request request) { return GetEngine()->AddRequest(std::move(request)); }
10551055
/*! \brief Redirection to `Engine::AbortRequest`. */

cpp/serve/engine_actions/auto_spec_decode.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class AutoSpecDecodeActionObj : public EngineActionObj {
8080
EngineAction EngineAction::AutoSpecDecode(std::vector<EngineAction> spec_decode_actions_,
8181
std::vector<EngineAction> batch_decode_actions_,
8282
EngineConfig engine_config) {
83-
return EngineAction(make_object<AutoSpecDecodeActionObj>(
83+
return EngineAction(tvm::ffi::make_object<AutoSpecDecodeActionObj>(
8484
Array<EngineAction>(spec_decode_actions_), Array<EngineAction>(batch_decode_actions_),
8585
std::move(engine_config)));
8686
}

cpp/serve/engine_actions/batch_decode.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ EngineAction EngineAction::BatchDecode(Array<Model> models, Tokenizer tokenizer,
317317
LogitProcessor logit_processor, Sampler sampler,
318318
EngineConfig engine_config,
319319
Optional<EventTraceRecorder> trace_recorder) {
320-
return EngineAction(make_object<BatchDecodeActionObj>(
320+
return EngineAction(tvm::ffi::make_object<BatchDecodeActionObj>(
321321
std::move(models), std::move(tokenizer), std::move(logit_processor), std::move(sampler),
322322
std::move(engine_config), std::move(trace_recorder)));
323323
}

cpp/serve/engine_actions/batch_draft.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ class BatchDraftActionObj : public EngineActionObj {
194194
if (engine_config_->spec_tree_width == 1) {
195195
return mstates[i]->request->generation_cfg;
196196
}
197-
auto spec_generation_cfg =
198-
make_object<GenerationConfigNode>(*(mstates[i]->request->generation_cfg.get()));
197+
auto spec_generation_cfg = tvm::ffi::make_object<GenerationConfigNode>(
198+
*(mstates[i]->request->generation_cfg.get()));
199199
spec_generation_cfg->top_logprobs = engine_config_->spec_tree_width;
200200
spec_generation_cfg->logprobs = true;
201201
spec_generation_cfg->temperature = 1.0;
@@ -397,7 +397,7 @@ EngineAction EngineAction::BatchDraft(Array<Model> models, LogitProcessor logit_
397397
DraftTokenWorkspaceManager draft_token_workspace_manager,
398398
EngineConfig engine_config,
399399
Optional<EventTraceRecorder> trace_recorder) {
400-
return EngineAction(make_object<BatchDraftActionObj>(
400+
return EngineAction(tvm::ffi::make_object<BatchDraftActionObj>(
401401
std::move(models), std::move(logit_processor), std::move(sampler),
402402
std::move(model_workspaces), std::move(draft_token_workspace_manager),
403403
std::move(engine_config), std::move(trace_recorder)));

cpp/serve/engine_actions/batch_jumpforward.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class BatchJumpForwardActionObj : public EngineActionObj {
230230

231231
EngineAction EngineAction::BatchJumpForward(Array<Model> models, Tokenizer tokenizer,
232232
Optional<EventTraceRecorder> trace_recorder) {
233-
return EngineAction(make_object<BatchJumpForwardActionObj>(
233+
return EngineAction(tvm::ffi::make_object<BatchJumpForwardActionObj>(
234234
std::move(models), std::move(tokenizer), std::move(trace_recorder)));
235235
}
236236

0 commit comments

Comments
 (0)