MCPcopy Create free account
hub / github.com/andrewkchan/deepseek.cpp / run_passkey

Function run_passkey

src/main.cpp:433–512  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

431}
432
433void run_passkey(
434 Session& session,
435 const int n_junk,
436 const int passkey_pos
437) {
438 Model& model = session.model;
439 InferenceState& state = session.state;
440 Sampler& sampler = session.sampler;
441 Tokenizer& tokenizer = session.tokenizer;
442
443 std::cout << "Model active bytes with full context window: " << model.active_bytes(model.config->max_seq_len) << std::endl;
444
445 const std::string PROMPT_PREFIX =
446 "There is an important info hidden inside a lot of irrelevant text. "
447 "Find it and memorize them. I will quiz you about the important information there.";
448 const std::string PROMPT_SUFFIX = " What is the pass key? The pass key is";
449
450 const int passkey = std::rand() % 50000 + 1;
451 const int pos = passkey_pos == -1 ? std::rand() % n_junk : passkey_pos;
452
453 std::string prompt = PROMPT_PREFIX;
454 for (int i = 0; i < n_junk; i++) {
455 if (i % n_junk == pos) {
456 prompt += " The pass key is " + std::to_string(passkey) + ". Remember it. " + std::to_string(passkey) + " is the pass key.";
457 }
458 prompt += " The grass is green. The sky is blue. The sun is yellow. Here we go. There and back again.";
459 }
460 prompt += PROMPT_SUFFIX;
461
462 std::vector<int> encoding;
463 {
464 uint64_t encode_start_ms = get_timestamp_ms();
465 encoding = tokenizer.encode(prompt, true);
466 uint64_t encode_end_ms = get_timestamp_ms();
467
468 uint64_t encoding_ms = encode_end_ms - encode_start_ms;
469 std::cout << fmt::format(
470 "Encoding stats: ({} tokens, throughput: {:.5}tok/s, latency: {:.5}s/tok, total: {:.5}s)\n",
471 encoding.size(),
472 encoding.size() / (encoding_ms / 1000.0),
473 (encoding_ms / 1000.0) / encoding.size(),
474 encoding_ms / 1000.0
475 ) << std::endl;
476 }
477
478 // Allow max 16 steps to generate passkey
479 const size_t MAX_GENERATION_STEPS = 16;
480
481 std::cout << fmt::format(
482 "Passkey test:\n"
483 " prompt: {} tokens\n"
484 " passkey: {}\n"
485 " passkey token index: ~{}\n",
486 encoding.size(),
487 passkey,
488 (int)(((float)pos) / n_junk * encoding.size())
489 ) << std::endl;
490

Callers 2

run_interactiveFunction · 0.85
mainFunction · 0.85

Calls 6

get_timestamp_msFunction · 0.85
active_bytesMethod · 0.80
encodeMethod · 0.80
forwardMethod · 0.80
sampleMethod · 0.80
decode_oneMethod · 0.80

Tested by

no test coverage detected