Skip to content

Commit 10251d9

Browse files
CVS-167152: fixed CLIPTextModelWithProjection creation in Python (openvinotoolkit#2169)
CVS-167152
1 parent 6245fcc commit 10251d9

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/python/openvino_genai/py_openvino_genai.pyi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,27 @@ class CLIPTextModelWithProjection(CLIPTextModel):
275275
"""
276276
CLIPTextModelWithProjection class.
277277
"""
278+
@typing.overload
279+
def __init__(self, root_dir: os.PathLike) -> None:
280+
"""
281+
CLIPTextModelWithProjection class
282+
root_dir (os.PathLike): Model root directory.
283+
"""
284+
@typing.overload
285+
def __init__(self, root_dir: os.PathLike, device: str, **kwargs) -> None:
286+
"""
287+
CLIPTextModelWithProjection class
288+
root_dir (os.PathLike): Model root directory.
289+
device (str): Device on which inference will be done.
290+
kwargs: Device properties.
291+
"""
292+
@typing.overload
293+
def __init__(self, model: CLIPTextModelWithProjection) -> None:
294+
"""
295+
CLIPText model
296+
CLIPTextModelWithProjection class
297+
model (CLIPTextModelWithProjection): CLIPText model with projection
298+
"""
278299
class CacheEvictionConfig:
279300
"""
280301

src/python/py_image_generation_models.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,40 @@ void init_clip_text_model(py::module_& m) {
9898
}
9999

100100
void init_clip_text_model_with_projection(py::module_& m) {
101-
auto clip_text_model_with_projection = py::class_<ov::genai::CLIPTextModelWithProjection, ov::genai::CLIPTextModel>(m, "CLIPTextModelWithProjection", "CLIPTextModelWithProjection class.");
101+
py::class_<ov::genai::CLIPTextModelWithProjection, ov::genai::CLIPTextModel>(m, "CLIPTextModelWithProjection", "CLIPTextModelWithProjection class.")
102+
.def(py::init([](const std::filesystem::path& root_dir) {
103+
ScopedVar env_manager(pyutils::ov_tokenizers_module_path());
104+
return std::make_unique<ov::genai::CLIPTextModelWithProjection>(root_dir);
105+
}),
106+
py::arg("root_dir"), "Model root directory",
107+
R"(
108+
CLIPTextModelWithProjection class
109+
root_dir (os.PathLike): Model root directory.
110+
)")
111+
.def(py::init([](
112+
const std::filesystem::path& root_dir,
113+
const std::string& device,
114+
const py::kwargs& kwargs
115+
) {
116+
ScopedVar env_manager(pyutils::ov_tokenizers_module_path());
117+
return std::make_unique<ov::genai::CLIPTextModelWithProjection>(root_dir, device, pyutils::kwargs_to_any_map(kwargs));
118+
}),
119+
py::arg("root_dir"), "Model root directory",
120+
py::arg("device"), "Device on which inference will be done",
121+
R"(
122+
CLIPTextModelWithProjection class
123+
root_dir (os.PathLike): Model root directory.
124+
device (str): Device on which inference will be done.
125+
kwargs: Device properties.
126+
)")
127+
.def(py::init([](const ov::genai::CLIPTextModelWithProjection& model) {
128+
return std::make_unique<ov::genai::CLIPTextModelWithProjection>(model);
129+
}),
130+
py::arg("model"), "CLIPText model"
131+
R"(
132+
CLIPTextModelWithProjection class
133+
model (CLIPTextModelWithProjection): CLIPText model with projection
134+
)");
102135
}
103136

104137
void init_t5_encoder_model(py::module_& m) {

0 commit comments

Comments
 (0)