@@ -11,7 +11,7 @@ std::pair<std::string, ov::Tensor> decrypt_model(const std::filesystem::path& mo
1111 std::ifstream model_file (model_dir / model_file_name);
1212 std::ifstream weights_file ();
1313 if (!model_file.is_open ()) {
14- throw std::runtime_error (" Cannot open model or weights file" );
14+ throw std::runtime_error (" Cannot open model file" );
1515 }
1616 std::string model_str ((std::istreambuf_iterator<char >(model_file)), std::istreambuf_iterator<char >());
1717
@@ -30,6 +30,39 @@ ov::genai::Tokenizer decrypt_tokenizer(const std::filesystem::path& models_path)
3030 return ov::genai::Tokenizer (tok_model_str, tok_weights_tensor, detok_model_str, detok_weights_tensor);
3131}
3232
33+ static const char codec_key[] = {0x30 , 0x60 , 0x70 , 0x02 , 0x04 , 0x08 , 0x3F , 0x6F , 0x72 , 0x74 , 0x78 , 0x7F };
34+
35+ std::string codec_xor (const std::string& source_str) {
36+ auto key_size = sizeof (codec_key);
37+ int key_idx = 0 ;
38+ std::string dst_str = source_str;
39+ for (char & c : dst_str) {
40+ c ^= codec_key[key_idx % key_size];
41+ key_idx++;
42+ }
43+ return dst_str;
44+ }
45+
46+ std::string encryption_callback (const std::string& source_str) {
47+ return codec_xor (source_str);
48+ }
49+
50+ std::string decryption_callback (const std::string& source_str) {
51+ return codec_xor (source_str);
52+ }
53+
54+ auto get_config_for_cache_encryption () {
55+ ov::AnyMap config;
56+ config.insert ({ov::cache_dir (" llm_cache" )});
57+ ov::EncryptionCallbacks encryption_callbacks;
58+ // use XOR-based encryption as an example
59+ encryption_callbacks.encrypt = encryption_callback;
60+ encryption_callbacks.decrypt = decryption_callback;
61+ config.insert (ov::cache_encryption_callbacks (encryption_callbacks));
62+ config.insert (ov::cache_mode (ov::CacheMode::OPTIMIZE_SIZE));
63+ return config;
64+ }
65+
3366bool print_subword (std::string&& subword) {
3467 return !(std::cout << subword << std::flush);
3568}
@@ -61,7 +94,7 @@ int main(int argc, char* argv[]) try {
6194 if (device == " GPU" ) {
6295 // Cache compiled models on disk for GPU to save time on the
6396 // next run. It's not beneficial for CPU.
64- enable_compile_cache. insert ({ ov::cache_dir ( " vlm_cache " )} );
97+ enable_compile_cache = get_config_for_cache_encryption ( );
6598 }
6699 ov::genai::VLMPipeline pipe (models_map, tokenizer, models_path, device, enable_compile_cache);
67100
0 commit comments