Scroll Top

Gemma (2b-v2)

C++ (Windows, Linux, MacOS / CUDA and Metal accelerated) port of https://github.com/google/gemma_pytorch.git.

Example Input & Outputs

Inputs Outputs
Which is your favorite Lord of the Rings movie? As an AI, I don’t have personal preferences like a favorite movie.

However, I can tell you that the Lord of the Rings movies are generally considered to be very well-made and beloved by many fans.

Here’s a breakdown of some common opinions:

* **The Fellowship of the Ring:** Many consider this the most faithful adaptation of the book, capturing the epic scope and emotional depth.
* **The Two Towers:** This film is praised for its action sequences and the introduction of new characters like Merry and Pippin.
* **The Return of the King:** This film is often considered the most visually stunning and emotionally resonant, culminating in a satisfying conclusion to the story.

Ultimately, the best Lord of the Rings movie for you depends on your personal preferences.

Demo Code

 1#include "blace_ai.h"
 2#include <fstream>
 3#include <iostream>
 4
 5// include the models you want to use
 6#include "gemma_v2_2b_v2_v1_ALL_export_version_v17.h"
 7
 8int main() {
 9  ::blace::workload_management::BlaceWorld blace;
10
11  auto gemma = blace::util::registerModel(
12      gemma_v2_2b_v2_v1_ALL_export_version_v17, blace::util::getPathToExe());
13
14  blace::ml_core::InferenceArgsCollection infer_args;
15  infer_args.inference_args.device = blace::util::get_accelerator().value();
16
17  std::vector<std::string> questions = {
18      "What is the answer to life?", "Will ai rule the world?",
19      "Which is your favorite lord of the rings movie?"};
20
21  for (auto str : questions) {
22    auto text_t = CONSTRUCT_OP(blace::ops::FromTextOp(str));
23
24    auto output_len = CONSTRUCT_OP(blace::ops::FromIntOp(200));
25    auto temperature = CONSTRUCT_OP(blace::ops::FromFloatOp(0.));
26    auto top_p = CONSTRUCT_OP(blace::ops::FromFloatOp(0.9));
27    auto top_k = CONSTRUCT_OP(blace::ops::FromIntOp(50));
28
29    // construct inference operation
30    auto infer_op = CONSTRUCT_OP(blace::ops::InferenceOp(
31        gemma_v2_2b_v2_v1_ALL_export_version_v17_IDENT,
32        {text_t, output_len, temperature, top_p, top_k}, infer_args, 0));
33
34    blace::computation_graph::GraphEvaluator evaluator(infer_op);
35    auto answer = evaluator.evaluateToString().value();
36    std::cout << "Answer: " << answer << std::endl;
37
38    // writes text to file
39    std::ofstream out("answer.txt");
40    out << answer;
41    out.close();
42  }
43
44  return 0;
45}

Follow the 5 minute instructions to build and run the demo.

Tested on version v0.9.51 of blace.ai sdk. Might also work on newer or older releases (check if release notes of blace.ai state breaking changes).

Artifacts

Payload Demo Project Header

License