Skip to content

Commit

Permalink
[ci] Allows build project with JDK 21 (#2903)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu authored Jan 5, 2024
1 parent 54f5176 commit fcfc928
Show file tree
Hide file tree
Showing 41 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/ai/djl/modality/Classifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Classifications implements JsonSerializable, Ensembleable<Classific
@SuppressWarnings("serial")
protected List<Double> probabilities;

private int topK;
protected int topK;

/**
* Constructs a {@code Classifications} using a parallel list of classNames and probabilities.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CategoryMask implements JsonSerializable {
.registerTypeAdapter(CategoryMask.class, new SegmentationSerializer())
.create();

private List<String> classes;
private transient List<String> classes;
private int[][] mask;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DetectedObjects(
List<String> classNames, List<Double> probabilities, List<BoundingBox> boundingBoxes) {
super(classNames, probabilities);
this.boundingBoxes = boundingBoxes;
setTopK(Integer.MAX_VALUE);
this.topK = Integer.MAX_VALUE;
}

/** {@inheritDoc} */
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/modality/nlp/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public abstract class Decoder extends AbstractBlock {
* @param block the block to be used to decode
* @param version the version to use for parameter and metadata serialization
*/
@SuppressWarnings("this-escape")
public Decoder(byte version, Block block) {
super(version);
this.block = addChildBlock("Block", block);
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/modality/nlp/Encoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public abstract class Encoder extends AbstractBlock {
* @param version the version to use for parameter and metadata serialization
* @param block the encoder block
*/
@SuppressWarnings("this-escape")
public Encoder(byte version, Block block) {
super(version);
this.block = addChildBlock("Block", block);
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/modality/nlp/EncoderDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class EncoderDecoder extends AbstractBlock {
* @param encoder the {@link Encoder}
* @param decoder the {@link Decoder}
*/
@SuppressWarnings("this-escape")
public EncoderDecoder(Encoder encoder, Decoder decoder) {
super(VERSION);
this.encoder = addChildBlock("Encoder", encoder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class TrainableTextEmbedding extends AbstractBlock implements TextEmbeddi
*
* @param wordEmbedding the word embedding to embed each word
*/
@SuppressWarnings("this-escape")
public TrainableTextEmbedding(TrainableWordEmbedding wordEmbedding) {
this.trainableWordEmbedding = addChildBlock("trainableWordEmbedding", wordEmbedding);
}
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/ndarray/BaseNDManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public abstract class BaseNDManager implements NDManager {
protected AtomicBoolean closed = new AtomicBoolean(false);
protected AtomicBoolean capped = new AtomicBoolean(false);

@SuppressWarnings("this-escape")
protected BaseNDManager(NDManager parent, Device device) {
this.parent = parent;
this.device = device == null ? defaultDevice() : device;
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/ndarray/NDScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class NDScope implements AutoCloseable {
private IdentityHashMap<NDArray, NDArray> resources;

/** Constructs a new {@code NDScope} instance. */
@SuppressWarnings("this-escape")
public NDScope() {
resources = new IdentityHashMap<>();
SCOPE_STACK.get().addLast(this);
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/ai/djl/nn/ParallelBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public ParallelBlock(Function<List<NDList>, NDList> function) {
* @param function the function to define how the parallel branches are combined
* @param blocks the blocks that form each of the parallel branches
*/
@SuppressWarnings("this-escape")
public ParallelBlock(Function<List<NDList>, NDList> function, List<Block> blocks) {
super(VERSION);
this.function = function;
Expand All @@ -74,6 +75,7 @@ public ParallelBlock(Function<List<NDList>, NDList> function, List<Block> blocks
* @param blocks the array of blocks to add
* @return this block
*/
@SuppressWarnings("this-escape")
public final ParallelBlock addAll(Block... blocks) {
return addAll(Arrays.asList(blocks));
}
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/nn/convolutional/Convolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public abstract class Convolution extends AbstractBlock {
*
* @param builder the {@code Builder} that has the necessary configurations
*/
@SuppressWarnings("this-escape")
public Convolution(ConvolutionBuilder<?> builder) {
super(VERSION);
kernelShape = builder.kernelShape;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public abstract class Deconvolution extends AbstractBlock {
*
* @param builder the {@code Builder} that has the necessary configurations
*/
@SuppressWarnings("this-escape")
public Deconvolution(DeconvolutionBuilder<?> builder) {
kernelShape = builder.kernelShape;
stride = builder.stride;
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/nn/core/ConstantEmbedding.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ConstantEmbedding extends AbstractBlock implements AbstractIndexedE
*
* @param embedding the value to return for all embeddings
*/
@SuppressWarnings("this-escape")
public ConstantEmbedding(NDArray embedding) {
this.embedding = embedding;
freezeParameters(true);
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/ai/djl/nn/core/Embedding.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public abstract class Embedding<T> extends AbstractBlock implements AbstractInde

protected Parameter embedding;

@SuppressWarnings("this-escape")
protected Embedding(BaseBuilder<T, ?> baseBuilder) {
super(VERSION);
embeddingSize = baseBuilder.embeddingSize;
Expand Down Expand Up @@ -91,6 +92,7 @@ protected Embedding(NDArray embedding) {
* @param embedding the embedding array
* @param format whether to compute row sparse gradient in the backward calculation
*/
@SuppressWarnings("this-escape")
protected Embedding(NDArray embedding, SparseFormat format) {
super(VERSION);
numEmbeddings = Math.toIntExact(embedding.getShape().get(0));
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/nn/core/Linear.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class Linear extends AbstractBlock {
private Parameter weight;
private Parameter bias;

@SuppressWarnings("this-escape")
protected Linear(Builder builder) {
super(VERSION);
units = builder.units;
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/nn/core/Prelu.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Prelu extends AbstractBlock {
private Parameter alpha;

/** Creates a Parametric ReLU Block. */
@SuppressWarnings("this-escape")
public Prelu() {
super(VERSION);
alpha =
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/nn/norm/LayerNorm.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class LayerNorm extends AbstractBlock {
protected Parameter gamma;
protected Parameter beta;

@SuppressWarnings("this-escape")
protected LayerNorm(Builder builder) {
epsilon = builder.epsilon;
scale = builder.scale;
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/nn/recurrent/RecurrentBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public abstract class RecurrentBlock extends AbstractBlock {
*
* @param builder the {@code Builder} that has the necessary configurations
*/
@SuppressWarnings("this-escape")
public RecurrentBlock(BaseBuilder<?> builder) {
super(VERSION);
stateSize = builder.stateSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class BertMaskedLanguageModelBlock extends AbstractBlock {
* @param bertBlock the bert block to create the task for
* @param hiddenActivation the activation to use for the hidden layer
*/
@SuppressWarnings("this-escape")
public BertMaskedLanguageModelBlock(
BertBlock bertBlock, Function<NDArray, NDArray> hiddenActivation) {
super(VERSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class BertNextSentenceBlock extends AbstractBlock {
private Linear binaryClassifier;

/** Creates a next sentence block. */
@SuppressWarnings("this-escape")
public BertNextSentenceBlock() {
binaryClassifier =
addChildBlock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class BertPretrainingBlock extends AbstractBlock {
*
* @param builder a builder with a bert configuration
*/
@SuppressWarnings("this-escape")
public BertPretrainingBlock(final BertBlock.Builder builder) {
this.bertBlock = addChildBlock("Bert", builder.build());
this.mlBlock =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PointwiseFeedForwardBlock extends SequentialBlock {
* @param activationFunction the activation function to use for the hidden layers (not applied
* to output)
*/
@SuppressWarnings("this-escape")
public PointwiseFeedForwardBlock(
List<Integer> hiddenSizes,
int outputSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class TransformerEncoderBlock extends AbstractBlock {
* @param dropoutProbability dropout probability
* @param activationFunction activation function
*/
@SuppressWarnings("this-escape")
public TransformerEncoderBlock(
int embeddingSize,
int headCount,
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/ai/djl/repository/zoo/DefaultModelZoo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class DefaultModelZoo extends ModelZoo {
private static final Logger logger = LoggerFactory.getLogger(DefaultModelZoo.class);

/** Constructs a new {@code LocalModelZoo} instance. */
@SuppressWarnings("this-escape")
public DefaultModelZoo() {
String locations = System.getProperty("ai.djl.repository.zoo.location");
if (locations != null) {
Expand All @@ -41,6 +42,7 @@ public DefaultModelZoo() {
*
* @param locations a comma separated urls where the models to be loaded from
*/
@SuppressWarnings("this-escape")
public DefaultModelZoo(String locations) {
parseLocation(locations);
}
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/training/Trainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class Trainer implements AutoCloseable {
* @param model the model the trainer will train on
* @param trainingConfig the configuration used by the trainer
*/
@SuppressWarnings("this-escape")
public Trainer(Model model, TrainingConfig trainingConfig) {
this.model = model;
manager = model.getNDManager().newSubManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public final class PaddingStackBatchifier implements Batchifier {

private static final long serialVersionUID = 1L;

private List<Integer> arraysToPad;
private List<Integer> dimsToPad;
private transient List<Integer> arraysToPad;
private transient List<Integer> dimsToPad;
private transient List<NDArraySupplier> paddingSuppliers;
private List<Integer> paddingSizes;
private transient List<Integer> paddingSizes;
private boolean includeValidLengths;

private PaddingStackBatchifier(Builder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public ListFeatures(int initialCapacity) {
*
* @param source the source list
*/
@SuppressWarnings("this-escape")
public ListFeatures(List<String> source) {
super(source.size());
addAll(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class LgbmSymbolBlock extends AbstractSymbolBlock implements AutoCloseabl
* @param iterations the number of iterations the model was trained for
* @param handle the Booster handle
*/
@SuppressWarnings("this-escape")
public LgbmSymbolBlock(LgbmNDManager manager, int iterations, SWIGTYPE_p_p_void handle) {
this.handle = new AtomicReference<>(handle);
this.iterations = iterations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class XgbSymbolBlock extends AbstractSymbolBlock implements AutoCloseable
* @param manager the manager to use for the block
* @param handle the Booster handle
*/
@SuppressWarnings("this-escape")
public XgbSymbolBlock(XgbNDManager manager, long handle) {
this.handle = new AtomicReference<>(handle);
this.manager = manager;
Expand Down
5 changes: 5 additions & 0 deletions engines/mxnet/jnarator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ dependencies {
checkstyleMain.source = 'src/main/java'
pmdMain.source = 'src/main/java'

compileJava {
options.compilerArgs.clear()
options.compilerArgs << "--release" << "11" << "-proc:none" << "-Xlint:all,-options,-static"
}

jar {
manifest {
attributes (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public void writeNativeSize() throws IOException {
writer.append(" public NativeSizeByReference() {\n");
writer.append(" this(new NativeSize(0));\n");
writer.append(" }\n\n");
writer.append(" @SuppressWarnings(\"this-escape\")\n");
writer.append(" public NativeSizeByReference(NativeSize value) {\n");
writer.append(" super(NativeSize.SIZE);\n");
writer.append(" setValue(value);\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class CachedOp extends NativeResource<Pointer> {
* @param dataIndices the input data names required by the model and their corresponding
* location
*/
@SuppressWarnings("this-escape")
public CachedOp(
Pointer handle,
MxNDManager manager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class MxParameterServer extends NativeResource<Pointer> implements Parame
*
* @param optimizer the optimizer to use for the parameter server updates
*/
@SuppressWarnings("this-escape")
public MxParameterServer(Optimizer optimizer) {
super(createdKVStore());
callback = new OptimizerCallback(optimizer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class OrtSymbolBlock extends AbstractSymbolBlock implements AutoCloseable
* @param session the {@link OrtSession} contains the model information
* @param manager the {@link NDManager} to holds the NDArray
*/
@SuppressWarnings("this-escape")
public OrtSymbolBlock(OrtSession session, OrtNDManager manager) {
this.session = session;
this.manager = manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class PtNDArray extends NativeResource<Long> implements NDArray {
* @param manager the manager to attach the new array to
* @param handle the pointer to the native PyTorch memory
*/
@SuppressWarnings("this-escape")
public PtNDArray(PtNDManager manager, long handle) {
super(handle);
this.manager = manager;
Expand All @@ -76,6 +77,7 @@ public PtNDArray(PtNDManager manager, long handle) {
* @param handle the pointer to the native PyTorch memory
* @param data the direct buffer of the data
*/
@SuppressWarnings("this-escape")
public PtNDArray(PtNDManager manager, long handle, ByteBuffer data) {
super(handle);
this.manager = manager;
Expand All @@ -93,6 +95,7 @@ public PtNDArray(PtNDManager manager, long handle, ByteBuffer data) {
* @param strs the string array
* @param shape the {@link Shape} of the {@link NDArray}
*/
@SuppressWarnings("this-escape")
public PtNDArray(PtNDManager manager, String[] strs, Shape shape) {
super(-1L);
this.manager = manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class PtSymbolBlock extends AbstractSymbolBlock implements AutoCloseable
* @param manager the manager to use for the block
* @param handle the module handle
*/
@SuppressWarnings("this-escape")
public PtSymbolBlock(PtNDManager manager, long handle) {
this(manager);
this.handle = new AtomicReference<>(handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -129,7 +130,9 @@ public void testWord2Vec() throws IOException, MalformedModelException, ModelNot
public void testBlazingText() throws IOException, ModelException {
TestRequirements.nightly();

URL url = new URL("https://resources.djl.ai/test-models/blazingtext_classification.bin");
URL url =
URI.create("https://resources.djl.ai/test-models/blazingtext_classification.bin")
.toURL();
Path path = Paths.get("build/tmp/model");
Path modelFile = path.resolve("text_classification.bin");
if (!Files.exists(modelFile)) {
Expand Down
4 changes: 3 additions & 1 deletion jacoco/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ dependencies {
jacocoAggregation project(":extensions:tokenizers")
jacocoAggregation project(":extensions:tablesaw")
jacocoAggregation project(":extensions:timeseries")
jacocoAggregation project(":extensions:spark")
if (JavaVersion.current() < JavaVersion.VERSION_19) {
jacocoAggregation project(":extensions:spark")
}
jacocoAggregation project(":integration")
jacocoAggregation project(":model-zoo")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Mlp(int input, int output, int[] hidden) {
* @param hidden the sizes of all of the hidden layers
* @param activation the activation function to use
*/
@SuppressWarnings("this-escape")
public Mlp(int input, int output, int[] hidden, Function<NDList, NDList> activation) {
add(Blocks.batchFlattenBlock(input));
for (int hiddenSize : hidden) {
Expand Down
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ include ':extensions:sentencepiece'
include ':extensions:tokenizers'
include ':extensions:tablesaw'
include ':extensions:timeseries'
include ':extensions:spark'
if (JavaVersion.current() < JavaVersion.VERSION_21) {
include ':extensions:spark'
}
include ':integration'
include ':model-zoo'
include ':testing'
Expand Down
Loading

0 comments on commit fcfc928

Please sign in to comment.