Skip to content

Commit aac8598

Browse files
authored
Bart (apache#14)
2 parents cc4ef4d + 97214e2 commit aac8598

20 files changed

+2154
-87
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@ jobs:
1919
source ~/venv/frontend-env/bin/activate
2020
pip install --force-reinstall .
2121
cd scripts && BUILD_DIR=~/frontend ./compile_longobj.sh && cd ..
22-
- name: Test with pytest
22+
- name: install dependency
2323
run: |
2424
source /opt/spack/share/spack/setup-env.sh
2525
spack load cuda@11.8.0 /jb4mlxg
2626
spack load python@3.9.12%gcc@=11.3.0
2727
source ~/venv/frontend-env/bin/activate
2828
pip install --upgrade -r requirements.txt -f https://download.pytorch.org/whl/torch_stable.html
29+
if ! pip show transformers &> /dev/null; then
30+
pip install transformers==v4.29.1
31+
fi
32+
- name: Test with pytest
33+
run: |
34+
source /opt/spack/share/spack/setup-env.sh
35+
spack load cuda@11.8.0 /jb4mlxg
36+
spack load python@3.9.12%gcc@=11.3.0
37+
source ~/venv/frontend-env/bin/activate
2938
srun --exclusive ./scripts/pytest_with_preload.sh -vs test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.vscode
33
build
44
__pycache__
5-
*.so
5+
*.so
6+
test/simple.py

frontend/c_api.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,8 @@ def parse_rangeiterobject(obj: Any) -> Tuple[int, int, int, int]:
8080

8181

8282
def make_rangeiterobject(start: int, stop: int, step: int) -> Any:
83+
pass
84+
85+
86+
def get_from_freevars(frame: FrameType, idx: int) -> Any:
8387
pass

frontend/csrc/frame_evaluation.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#define PY_SSIZE_T_CLEAN
22
#include "csrc.h"
33
#include <Python.h>
4+
#include <cellobject.h>
45
#include <frameobject.h>
56
#include <map>
67
#include <object.h>
@@ -466,6 +467,24 @@ static PyObject *is_bound_method(PyObject *self, PyObject *args) {
466467
}
467468
}
468469

470+
static PyObject *get_from_freevars(PyObject *self, PyObject *args) {
471+
PyObject *frame;
472+
int index;
473+
if (!PyArg_ParseTuple(args, "Oi", &frame, &index)) {
474+
PRINT_PYERR;
475+
PyErr_SetString(PyExc_TypeError,
476+
"invalid parameter in get_from_freevars");
477+
return NULL;
478+
}
479+
PyFrameObject *f = (PyFrameObject *)frame;
480+
PyObject *value = f->f_localsplus[index + f->f_code->co_nlocals];
481+
if (value == NULL) {
482+
value = null_object;
483+
}
484+
Py_INCREF(value);
485+
return value;
486+
}
487+
469488
static PyMethodDef _methods[] = {
470489
{"set_eval_frame", set_eval_frame, METH_VARARGS, NULL},
471490
{"set_skip_files", set_skip_files, METH_VARARGS, NULL},
@@ -491,6 +510,7 @@ static PyMethodDef _methods[] = {
491510
METH_VARARGS, NULL},
492511
{"get_code_map", get_code_map, METH_VARARGS, NULL},
493512
{"is_bound_method", is_bound_method, METH_VARARGS, NULL},
513+
{"get_from_freevars", get_from_freevars, METH_VARARGS, NULL},
494514
{"parse_rangeiterobject", frontend_csrc::parse_rangeiterobject,
495515
METH_VARARGS, NULL},
496516
{"make_rangeiterobject", frontend_csrc::make_rangeiterobject, METH_VARARGS,
@@ -512,5 +532,7 @@ PyMODINIT_FUNC PyInit_c_api(void) {
512532
CHECK(result == 0);
513533
Py_INCREF(Py_None);
514534
set_eval_frame_callback(Py_None);
515-
return PyModule_Create(&_module);
535+
536+
PyObject *m = PyModule_Create(&_module);
537+
return m;
516538
}

0 commit comments

Comments
 (0)