The following issues were found

aten/src/ATen/BatchingRegistrations.cpp
1 issues
syntax error
Error

Line: 1016

                return physical_args[0].getPhysicalToLogicalMap().apply(result);
}

TORCH_LIBRARY_IMPL(_, Batched, m) {
  m.fallback(torch::CppFunction::makeFromBoxedFunction<&batchedTensorForLoopFallback>());
}

TORCH_LIBRARY_IMPL(aten, Batched, m) {
  // NB: Ideally we would like some operators, like size.int, to "fallthrough"

            

Reported by Cppcheck.

caffe2/python/mpi_python.cc
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 40 Column: 7 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                  MPI_Bcast(&length, sizeof(length), MPI_CHAR, 0, comm);
    auto ptr = std::make_unique<char[]>(length);
    if (MPICommRank(comm) == 0) {
      memcpy(ptr.get(), str.data(), str.length());
    }
    MPI_Bcast(ptr.get(), length, MPI_CHAR, 0, comm);
    return std::string(ptr.get(), length);
  });
}

            

Reported by FlawFinder.

android/test_app/app/src/main/java/org/pytorch/testapp/LibtorchNativeClient.java
1 issues
All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 6

              import com.facebook.soloader.nativeloader.NativeLoader;
import com.facebook.soloader.nativeloader.SystemDelegate;

public final class LibtorchNativeClient {

  public static void loadAndForwardModel(final String modelPath) {
    NativePeer.loadAndForwardModel(modelPath);
  }


            

Reported by PMD.

android/test_app/app/src/main/java/org/pytorch/testapp/Constants.java
1 issues
Avoid really long classes.
Design

Line: 3

              package org.pytorch.testapp;

public class Constants {
  public static final String TAG = "PyTorchDemo";

  public static String[] IMAGENET_CLASSES =
      new String[] {
        "tench, Tinca tinca",
        "goldfish, Carassius auratus",

            

Reported by PMD.

android/pytorch_android/src/main/java/org/pytorch/NativePeer.java
1 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 14

                  PyTorchCodegenLoader.loadNativeLibs();
  }

  private final HybridData mHybridData;

  @DoNotStrip
  private static native HybridData initHybrid(
      String moduleAbsolutePath, Map<String, String> extraFiles, int deviceJniCode);


            

Reported by PMD.

android/pytorch_android/src/main/java/org/pytorch/LiteNativePeer.java
1 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 17

                  PyTorchCodegenLoader.loadNativeLibs();
  }

  private final HybridData mHybridData;

  private static native HybridData initHybrid(
      String moduleAbsolutePath, Map<String, String> extraFiles, int deviceJniCode);

  private static native HybridData initHybridAndroidAsset(

            

Reported by PMD.

android/pytorch_android/src/main/java/org/pytorch/LiteModuleLoader.java
1 issues
All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 6

              import android.content.res.AssetManager;
import java.util.Map;

public class LiteModuleLoader {

  /**
   * Loads a serialized TorchScript module from the specified path on the disk to run on specified
   * device. The model should be generated from this api _save_for_lite_interpreter().
   *

            

Reported by PMD.

caffe2/proto/gen_proto_typestubs_helper.py
1 issues
Missing module docstring
Error

Line: 1 Column: 1

              import ast

with open("../python/__init__.py", "r") as f:
    tree = ast.parse(f.read())

print("\nDeviceType = int\n")
print("# These are freedom-patched into caffe2_pb2 in caffe2/proto/__init__.py")
for stmt in tree.body:
    if not isinstance(stmt, ast.Assign):

            

Reported by Pylint.

caffe2/proto/__init__.py
1 issues
Missing module docstring
Error

Line: 1 Column: 1

              # NOTE: we have to import python protobuf here **before** we load cpp extension.
# Otherwise it breaks under certain build conditions if cpp implementation of
# protobuf is used. Presumably there's some registry in protobuf library and
# python side has to initialize the dictionary first, before static
# initialization in python extension does so. Otherwise, duplicated protobuf
# descriptors will be created and it can lead to obscure errors like
#   "Parameter to MergeFrom() must be instance of same class:
#    expected caffe2.NetDef got caffe2.NetDef."
#

            

Reported by Pylint.

caffe2/predictor/predictor_test.cc
1 issues
syntax error
Error

Line: 179

                std::unique_ptr<Predictor> p_;
};

TEST_F(PredictorTest, SimpleBatchSized) {
  auto inputData = randomTensor({1, 4}, ctx_.get());
  Predictor::TensorList input;
  auto tensor = BlobGetMutableTensor(inputData.get(), CPU);
  input.emplace_back(tensor->Alias());
  Predictor::TensorList output;

            

Reported by Cppcheck.