Decision Forest - Raspberry PI

I am not sure how to compile the yggdrasil c++ library on a raspberry pi 3b+ (armv7). I have tried just about everything I can think of and still it errors out. Is there any tips or documentation I can use for building the libraries required to run a tensorflow decision forest model on a raspberry pi armv7?

1 Like

@Jan can you share any insights here?

hi Joshua, this is super cool! We’ve discussed this among ourselves but never had the time to do it. Last time I used raspberrypie was > 8 years ago … and there was only a C compiler.

But maybe @Mathieu would be interested in trying ? (He may take a week to reply though)

Some considerations:

  • Some of the optimized inference engines do take advantage of things link AVX-2, but they could be disabled.

  • I’m not sure what kind of C++ compiler is available for the armv7.

  • Yggdrasil does depend on a few other libraries, not sure if they compile.

I’m assuming you are trying to have only the inference engine (to make model predictions, not to train) run in raspberry pi, right ? (although in principle training should work as well).

Let me suggest the following: add an “issue” in the Yggdrasil github, we’ll mark it as an enhancement. And maybe add more details of what are the errors there. No promises about timeline we would work on it, but having these models running on edge devices (including raspberry pi) is high on our wish-list.

1 Like

Yes we are only trying to run inference, the model has been trained using tfdf python library and exported.

The bazel building seems like it is trying to compile tensorflow core when I added into the tensorflow_io flag:
[775 / 1,124] 4 actions, 2 running
Compiling org_tensorflow/tensorflow/core/framework/; 16131s local
Compiling org_tensorflow/tensorflow/core/util/; 16113s local
[Sched] Compiling org_tensorflow/tensorflow/core/util/; 16131s
[Sched] Compiling org_tensorflow/tensorflow/core/util/; 16113s

I included the tensorflow_io flag because I was getting the filesystem error you guys mentioned below, however mine was not runtime segmentation fault, it was a bazel compiling error.

Segmentation fault when any program starts on std::filesystem::~path()
lstdc++fs is not linked. You are likely using GCC8 without TensorFlow. Update to GCC>=9 or use TensorFlow for IO (--config=use_tensorflow_io).

The compiler’s I have installed are g++ 8.4 & gcc 8.4

I also had to take out the build:linux_avx2 --copt=-mavx2 in the .bazelrc file because mavx2 is not a recognized command. So far I just want to run the model on a raspberry pi. Once I can do that and verify it’s working, I’ll start to integrate my model / project into bazel build system. But I have tried both the standalone example and the default method and both seem to fail. I can also provide my latest logs if that will help.

Little background: our team uses raspberry pi’s for prototyping and demoing. We need to use armv7 because of some older libraries required for the project.

Scratch my previous message below. I had forgotten, indeed we use TensorFlow librayr for IO, as you mentioned.

Maybe trying to remove the Tensorflow_io dependency ? It should be optional, if you don’t need it – and I assume you won’t need it in Raspberry PI.

This is odd. For Raspberry PI I assume you only want the C++ inference, by building Yggdrasil directly (GitHub - google/yggdrasil-decision-forests: A collection of state-of-the-art algorithms for the training, serving and interpretation of Decision Forest models.), there should be no dependencies to TensorFlow.

Notice the model you train with TensorFlow can be used by the C++ library in Yggdrasil – no conversions needed, the yggdrasil model is saved under assets/ subdirectory.

I can officially say for certain yggdrasil requires tensorflow and inorder to remove tensorflow from the framework you have to manually edit quite a bit of files (I think it was 5 total) it is possible but not as simple as just adding tensorflow to the exclude box.

Inference requires: #include “yggdrasil_decision_forests/model/model_library.h”

bazel dependency: “@ydf//yggdrasil_decision_forests/model:model_library”,
requires dependency: @ydf//yggdrasil_decision_forests/dataset:data_spec

dataspec requires:
external/ydf/yggdrasil_decision_forests/dataset/data_spec.h:31:10: fatal error: tensorflow/core/example/example.pb.h: No such file or directory
31 | #include “tensorflow/core/example/example.pb.h”

So I took out all the tensorflow related functions in multiple files. Finally got it to compile on x86_64.

if I try to cross compile using aarch64 or armv7 I get this error from protoc.

ERROR: /home/jw/.cache/bazel/_bazel_jw/9fd1adcb07b2b4c327079de6e005c167/external/ydf/yggdrasil_decision_forests/dataset/BUILD:394:18: Generating C++ proto_library @ydf//yggdrasil_decision_forests/dataset:example_proto failed (Exit 2): protoc failed: error executing command bazel-out/host/bin/external/com_google_protobuf/protoc ‘–proto_path=external/ydf’ ‘–cpp_out=bazel-out/k8-opt/bin/external/ydf’ … (remaining 5 argument(s) skipped)
bazel-out/host/bin/external/com_google_protobuf/protoc: 1: bazel-out/host/bin/external/com_google_protobuf/protoc: ELF�@�@@Xs=@8: not found
bazel-out/host/bin/external/com_google_protobuf/protoc: 2: bazel-out/host/bin/external/com_google_protobuf/protoc: cannot open n��!: No such file
bazel-out/host/bin/external/com_google_protobuf/protoc: 3: bazel-out/host/bin/external/com_google_protobuf/protoc: : not found
bazel-out/host/bin/external/com_google_protobuf/protoc: 4: bazel-out/host/bin/external/com_google_protobuf/protoc: S: not found
bazel-out/host/bin/external/com_google_protobuf/protoc: 5: bazel-out/host/bin/external/com_google_protobuf/protoc: �: not found
bazel-out/host/bin/external/com_google_protobuf/protoc: 6: bazel-out/host/bin/external/com_google_protobuf/protoc: �: not found
bazel-out/host/bin/external/com_google_protobuf/protoc: 7: bazel-out/host/bin/external/com_google_protobuf/protoc: Syntax error: word unexpected (expecting “)”)
Target //:beginner_cc failed to build
Use --verbose_failures to see the command lines of failed build steps.

the library giving the error is:

name = “prediction_proto”,
srcs = [“prediction.proto”],
deps = ["//yggdrasil_decision_forests/utils:distribution_proto"],

Is this the same thread as:

Indeed Yggdrasil imports the proto definitions from TensorFlow (tf.Example) – I wonder if we should make a copy of those so drop the dependency …

Btw, how are you compiling to armv7 ?

I suggest we follow this up on the github issue #10.

@Bhack: I quickly tried and failed to compile to armv7 … sorry, it’s not trivial, even though I’d not be suprised if all it takes will be a few lines of configuration … – If you find out pls let us know. Hopefully we will find some time this quarter. Again I’d suggest we follow up on the github above.

As I saw in the ticket It is similar to the old TF issue at:

I believe the error I was getting from bazel (the protoc) is the protoc was built with arm. If I point bazel to a cross compiler it builds everything using that cross-compiler. Then when it trys to run protoc to build the proto files. It realizes the binary is unreadable (“it” being bazel). Thus I get these weird symbol errors because protoc was built with the cross compiler.

So somehow (and I dont know bazel that well) I need to build the binaries with the cross compiler but keep protoc as x86_64.

I tried building native on a jetson and there just isn’t enough room. The bazel cache is huge even without tensorflow (IE: boost, absl, etc…)

my alternative for right now is just using SPORF (I guess that is what you guys used to create the hyper parameter best global first. It’s not giving the exact same results I got from tfdf but it’s progress in the right direction as I can run it on arm

Indeed it builds protoc to then compile the protos to .h/.cc files.

Now there is a flag for that in Bazel: --host_cpu, which is the target CPU for the host tools (like protoc) if I understand correctly (so maybe adding --host_cpu=k8 if compiling from the usual PC). But I haven’t done cross-compiling with Bazel before.

1 Like