Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Fast loads on python and liblemonade #43

Merged
merged 13 commits into from
Jan 19, 2022
17 changes: 12 additions & 5 deletions bindings/python/bergamot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class ServicePyAdapter {
: service_(make_service(config)) {}

std::shared_ptr<_Model> modelFromConfig(const std::string &config) {
return service_.createCompatibleModel(config);
auto parsedConfig = marian::bergamot::parseOptionsFromString(config);
return service_.createCompatibleModel(parsedConfig);
}

std::shared_ptr<_Model> modelFromConfigPath(const std::string &configPath) {
Expand Down Expand Up @@ -208,12 +209,18 @@ PYBIND11_MODULE(_bergamot, m) {

py::class_<Service::Config>(m, "ServiceConfig")
.def(py::init<>([](size_t numWorkers, bool cacheEnabled, size_t cacheSize,
size_t cacheMutexBuckets) {
return Service::Config{numWorkers, cacheEnabled, cacheSize,
cacheMutexBuckets};
size_t cacheMutexBuckets, std::string logging) {
Service::Config config;
config.numWorkers = numWorkers;
config.cacheEnabled = cacheEnabled;
config.cacheSize = cacheSize;
config.cacheMutexBuckets = cacheMutexBuckets;
config.logger.level = logging;
return config;
}),
py::arg("numWorkers") = 1, py::arg("cacheEnabled") = false,
py::arg("cacheSize") = 20000, py::arg("cacheMutexBuckets") = 1)
py::arg("cacheSize") = 20000, py::arg("cacheMutexBuckets") = 1,
py::arg("logLevel") = "off")
.def_readwrite("numWorkers", &Service::Config::numWorkers)
.def_readwrite("cacheEnabled", &Service::Config::cacheEnabled)
.def_readwrite("cacheSize", &Service::Config::cacheSize)
Expand Down
10 changes: 9 additions & 1 deletion bindings/python/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def embed_subparser(key: str, subparsers: argparse._SubParsersAction):
help="Number of worker threads to use to translate",
default=4,
)

translate.add_argument(
"--log-level",
type=str,
default="off",
help="Set verbosity level of logging: trace, debug, info, warn, err(or), critical, off",
)

# Tweak response-options for quick HTML in out via commandline
options = translate.add_argument_group("response-options")
options.add_argument("--html", type=bool, default=False)
Expand All @@ -54,7 +62,7 @@ def embed_subparser(key: str, subparsers: argparse._SubParsersAction):
def execute(args: argparse.Namespace):
# Build service

config = ServiceConfig(numWorkers=args.num_workers)
config = ServiceConfig(numWorkers=args.num_workers, logLevel=args.log_level)
service = Service(config)

models = [
Expand Down
10 changes: 2 additions & 8 deletions lemonade/lib/translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ void Translator::translate(std::string input, const std::string &source,
// FIXME
modelConfig->set("workspace", 128);

marian::timer::Timer bundleTimer;
marian::bergamot::MemoryBundle memoryBundle =
marian::bergamot::getMemoryBundleFromConfig(modelConfig);
std::cout << fmt::format("Bundle loading from disk {} seconds.\n",
bundleTimer.elapsed());
marian::timer::Timer timer;
model =
service_.createCompatibleModel(modelConfig, std::move(memoryBundle));
model = service_.createCompatibleModel(modelConfig);

std::cout << fmt::format("Model building from bundle took {} seconds.\n",
std::cerr << fmt::format("Model building from bundle took {} seconds.\n",
timer.elapsed());
manager_.cacheModel(m.code, model);
}
Expand Down