Skip to content

Commit

Permalink
add set_min_log_level function to python to change the loglevel from …
Browse files Browse the repository at this point in the history
…python wrapper.
  • Loading branch information
taku910 committed Dec 23, 2023
1 parent bd3925a commit 96aabae
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 81 deletions.
10 changes: 6 additions & 4 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.!

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.build_py import build_py as _build_py
import codecs
import os
import string
import subprocess
import sys
import os
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.build_py import build_py as _build_py

sys.path.append(os.path.join('.', 'test'))

Expand Down Expand Up @@ -94,6 +94,8 @@ def build_extension(self, ext):
else:
cflags.append('-Wl,-strip-all')
libs.append('-Wl,-strip-all')
if sys.platform == 'linux':
libs.append('-Wl,-Bsymbolic')
print('## cflags={}'.format(' '.join(cflags)))
print('## libs={}'.format(' '.join(libs)))
ext.extra_compile_args = cflags
Expand Down
4 changes: 4 additions & 0 deletions python/src/sentencepiece/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,9 @@ def Load(self, model_file=None, model_proto=None):

def SetRandomGeneratorSeed(seed):
return _sentencepiece.SetRandomGeneratorSeed(seed)

def SetMinLogLevel(v):
return _sentencepiece.SetMinLogLevel(v)
class SentencePieceTrainer(object):
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

Expand Down Expand Up @@ -1039,6 +1042,7 @@ def _batched_func(self, arg):
_add_snake_case(SentencePieceProcessor)
_add_snake_case(SentencePieceTrainer)
set_random_generator_seed = SetRandomGeneratorSeed
set_min_log_level = SetMinLogLevel

from ._version import __version__

Expand Down
1 change: 1 addition & 0 deletions python/src/sentencepiece/sentencepiece.i
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,7 @@ for m in [
_add_snake_case(SentencePieceProcessor)
_add_snake_case(SentencePieceTrainer)
set_random_generator_seed = SetRandomGeneratorSeed
set_min_log_level = SetMinLogLevel

from ._version import __version__

Expand Down
31 changes: 31 additions & 0 deletions python/src/sentencepiece/sentencepiece_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8429,6 +8429,36 @@ SWIGINTERN PyObject *_wrap_SetRandomGeneratorSeed(PyObject *self, PyObject *args
}


SWIGINTERN PyObject *_wrap_SetMinLogLevel(PyObject *self, PyObject *args) {
PyObject *resultobj = 0;
int arg1 ;
int val1 ;
int ecode1 = 0 ;
PyObject *swig_obj[1] ;

if (!args) SWIG_fail;
swig_obj[0] = args;
ecode1 = SWIG_AsVal_int(swig_obj[0], &val1);
if (!SWIG_IsOK(ecode1)) {
SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "SetMinLogLevel" "', argument " "1"" of type '" "int""'");
}
arg1 = static_cast< int >(val1);
{
try {
sentencepiece::SetMinLogLevel(arg1);
ReleaseResultObject(resultobj);
}
catch (const sentencepiece::util::Status &status) {
SWIG_exception(ToSwigError(status.code()), status.ToString().c_str());
}
}
resultobj = SWIG_Py_Void();
return resultobj;
fail:
return NULL;
}


SWIGINTERN PyObject *_wrap_SentencePieceTrainer__TrainFromString(PyObject *self, PyObject *args) {
PyObject *resultobj = 0;
absl::string_view arg1 ;
Expand Down Expand Up @@ -8800,6 +8830,7 @@ static PyMethodDef SwigMethods[] = {
{ "SentencePieceProcessor_swigregister", SentencePieceProcessor_swigregister, METH_O, NULL},
{ "SentencePieceProcessor_swiginit", SentencePieceProcessor_swiginit, METH_VARARGS, NULL},
{ "SetRandomGeneratorSeed", _wrap_SetRandomGeneratorSeed, METH_O, NULL},
{ "SetMinLogLevel", _wrap_SetMinLogLevel, METH_O, NULL},
{ "SentencePieceTrainer__TrainFromString", _wrap_SentencePieceTrainer__TrainFromString, METH_O, NULL},
{ "SentencePieceTrainer__TrainFromMap", _wrap_SentencePieceTrainer__TrainFromMap, METH_O, NULL},
{ "SentencePieceTrainer__TrainFromMap2", _wrap_SentencePieceTrainer__TrainFromMap2, METH_VARARGS, NULL},
Expand Down
Loading

0 comments on commit 96aabae

Please sign in to comment.