Make changes needed for new demo

This commit is contained in:
Justine Tunney 2023-06-15 23:22:49 -07:00
parent c3440d040c
commit e6b7c16a53
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
13 changed files with 96 additions and 47 deletions

View file

@ -212,7 +212,7 @@ static int on_missing_feature(const char *name) {
int main(int argc, char ** argv) {
MakeProcessNice();
verynice();
ShowCrashReports();
setvbuf(stdin, NULL, _IONBF, 0);

View file

@ -55,7 +55,7 @@ static const std::map<std::string, llama_ftype> LLAMA_FTYPE_MAP = {
// ./quantize models/llama/ggml-model.bin models/llama/ggml-model-quant.bin type [nthreads]
//
int main(int argc, char ** argv) {
MakeProcessNice();
verynice();
ShowCrashReports();
ggjt_v3();

View file

@ -359,6 +359,14 @@ class BaseServer:
"""
pass
def forked_request(self, request, client_address):
"""Called in child after os.fork() is called.
May be overridden.
"""
pass
def finish_request(self, request, client_address):
"""Finish one request by instantiating RequestHandlerClass."""
self.RequestHandlerClass(request, client_address, self)
@ -617,6 +625,7 @@ if hasattr(os, "fork"):
# This must never return, hence os._exit()!
status = 1
try:
self.forked_request(request, client_address)
self.finish_request(request, client_address)
status = 0
except Exception:

View file

@ -146,6 +146,18 @@ cosmo_crc32c(PyObject *self, PyObject *args)
return PyLong_FromUnsignedLong(crc);
}
PyDoc_STRVAR(verynice_doc,
"verynice($module)\n\
--\n\n\
Makes current process as low-priority as possible.");
static PyObject *
cosmo_verynice(PyObject *self, PyObject *args)
{
verynice();
Py_RETURN_NONE;
}
PyDoc_STRVAR(decimate_doc,
"decimate($module, bytes)\n\
--\n\n\
@ -202,6 +214,7 @@ PyDoc_STRVAR(pledge_doc,
--\n\n\
Permits syscall operations, e.g.\n\
\n\
>>> cosmo.pledge(None, None) # assert support\n\
>>> cosmo.pledge('stdio rpath tty', None)\n\
\n\
This function implements the OpenBSD pledge() API for\n\
@ -213,7 +226,7 @@ cosmo_pledge(PyObject *self, PyObject *args)
{
int e = errno;
const char *x, *y;
if (!PyArg_ParseTuple(args, "sz:pledge", &x, &y)) return 0;
if (!PyArg_ParseTuple(args, "zz:pledge", &x, &y)) return 0;
__pledge_mode = PLEDGE_PENALTY_RETURN_EPERM;
if (!pledge(x, y)) {
Py_RETURN_NONE;
@ -229,8 +242,9 @@ PyDoc_STRVAR(unveil_doc,
--\n\n\
Permits filesystem operations, e.g.\n\
\n\
>>> cosmo.unveil('.', 'rwcx')\n\
>>> cosmo.unveil(None, None)\n\
>>> cosmo.unveil('', None) # assert support\n\
>>> cosmo.unveil('.', 'rwcx') # permit current dir\n\
>>> cosmo.unveil(None, None) # commit policy\n\
\n\
This function implements the OpenBSD unveil() API for\n\
OpenBSD and Linux where we use Landlock LSM. Read the\n\
@ -239,11 +253,15 @@ Cosmopolitan Libc documentation to learn more.");
static PyObject *
cosmo_unveil(PyObject *self, PyObject *args)
{
int e = errno;
const char *x, *y;
int abi, e = errno;
if (!PyArg_ParseTuple(args, "zz:unveil", &x, &y)) return 0;
if (!unveil(x, y)) {
Py_RETURN_NONE;
if ((abi = unveil(x, y)) != -1) {
if (abi) {
return PyLong_FromUnsignedLong(abi);
} else {
Py_RETURN_NONE;
}
} else {
PyErr_SetString(PyExc_SystemError, strerror(errno));
errno = e;
@ -338,6 +356,7 @@ static PyMethodDef cosmo_methods[] = {
{"syscount", cosmo_syscount, METH_NOARGS, syscount_doc},
{"popcount", cosmo_popcount, METH_VARARGS, popcount_doc},
{"decimate", cosmo_decimate, METH_VARARGS, decimate_doc},
{"verynice", cosmo_verynice, METH_VARARGS, verynice_doc},
#ifdef __x86_64__
{"getcpucore", cosmo_getcpucore, METH_NOARGS, getcpucore_doc},
{"getcpunode", cosmo_getcpunode, METH_NOARGS, getcpunode_doc},

View file

@ -48,7 +48,7 @@ static const std::map<std::string, enum gptneox_ftype> GPTNEOX_FTYPE_MAP = {
// ./quantize models/llama/ggml-model.bin models/llama/ggml-model-quant.bin type
//
int main(int argc, char ** argv) {
MakeProcessNice();
verynice();
ShowCrashReports();
ggjt_v1();

View file

@ -99,7 +99,7 @@ int main(int argc, char ** argv) {
params.instruct = true;
params.interactive = true;
MakeProcessNice();
verynice();
ShowCrashReports();
if (gpt_params_parse(argc, argv, params) == false) { return 1; }
@ -137,7 +137,7 @@ int main(int argc, char ** argv) {
}
}
MakeProcessNice();
verynice();
ShowCrashReports();
// Always interactive for RedPajama chat model

View file

@ -84,7 +84,7 @@ int main(int argc, char ** argv) {
gpt_params params;
params.model = "./examples/redpajama/models/pythia/ggml-RedPajama-INCITE-Instruct-3B-v1-f16.bin";
MakeProcessNice();
verynice();
ShowCrashReports();
if (gpt_params_parse(argc, argv, params) == false) {

View file

@ -50,7 +50,7 @@ static const std::map<std::string, enum gptneox_ftype> GPTNEOX_FTYPE_MAP = {
// ./quantize models/llama/ggml-model.bin models/llama/ggml-model-quant.bin type
//
int main(int argc, char ** argv) {
MakeProcessNice();
verynice();
ShowCrashReports();
ggjt_v2();