Skip to content

Commit 82c87b0

Browse files
committed
Remove lint plugin
1 parent 113a072 commit 82c87b0

File tree

8 files changed

+168
-146
lines changed

8 files changed

+168
-146
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ The DL4J stack comprises of:
2828
- **ND4J**: General purpose linear algebra library with over 500 mathematical, linear algebra and deep learning operations. ND4J is based on the highly-optimized C++ codebase LibND4J that provides CPU (AVX2/512) and GPU (CUDA) support and acceleration by libraries such as OpenBLAS, OneDNN (MKL-DNN), cuDNN, cuBLAS, etc
2929
- **SameDiff** : Part of the ND4J library, SameDiff is our automatic differentiation / deep learning framework. SameDiff uses a graph-based (define then run) approach, similar to TensorFlow graph mode. Eager graph (TensorFlow 2.x eager/PyTorch) graph execution is planned. SameDiff supports importing TensorFlow frozen model format .pb (protobuf) models. Import for ONNX, TensorFlow SavedModel and Keras models are planned. Deeplearning4j also has full SameDiff support for easily writing custom layers and loss functions.
3030
- **DataVec**: ETL for machine learning data in a wide variety of formats and files (HDFS, Spark, Images, Video, Audio, CSV, Excel etc)
31-
- **Arbiter**: Library for hyperparameter search
3231
- **LibND4J** : C++ library that underpins everything. For more information on how the JVM accesses native arrays and operations refer to [JavaCPP](https://github.com/bytedeco/javacpp)
3332

3433
All projects in the DL4J ecosystem support Windows, Linux and macOS. Hardware support includes CUDA GPUs (10.0, 10.1, 10.2 except OSX), x86 CPU (x86_64, avx2, avx512), ARM CPU (arm, arm64, armhf) and PowerPC (ppc64le).

data-pipeline-examples/pom.xml

+1-24
Original file line numberDiff line numberDiff line change
@@ -220,30 +220,7 @@ information regarding copyright ownership.
220220
<target>${java.version}</target>
221221
</configuration>
222222
</plugin>
223-
<plugin>
224-
<groupId>com.lewisd</groupId>
225-
<artifactId>lint-maven-plugin</artifactId>
226-
<version>0.0.11</version>
227-
<configuration>
228-
<failOnViolation>true</failOnViolation>
229-
<onlyRunRules>
230-
<rule>DuplicateDep</rule>
231-
<rule>RedundantPluginVersion</rule>
232-
<!-- Rules incompatible with Java 9
233-
<rule>VersionProp</rule>
234-
<rule>DotVersionProperty</rule> -->
235-
</onlyRunRules>
236-
</configuration>
237-
<executions>
238-
<execution>
239-
<id>pom-lint</id>
240-
<phase>validate</phase>
241-
<goals>
242-
<goal>check</goal>
243-
</goals>
244-
</execution>
245-
</executions>
246-
</plugin>
223+
247224
<plugin>
248225
<groupId>org.codehaus.mojo</groupId>
249226
<artifactId>exec-maven-plugin</artifactId>

dl4j-examples/pom.xml

+2-25
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ information regarding copyright ownership.
3232
<description>A set of examples introducing the DL4J framework</description>
3333

3434
<properties>
35-
<dl4j-master.version>1.0.0-M2.1</dl4j-master.version>
35+
<dl4j-master.version>1.0.0-SNAPSHOT</dl4j-master.version>
3636
<!-- Change the nd4j.backend property to nd4j-cuda-X-platform to use CUDA GPUs -->
3737
<!-- <nd4j.backend>nd4j-cuda-10.2-platform</nd4j.backend> -->
3838
<nd4j.backend>nd4j-native</nd4j.backend>
@@ -218,30 +218,7 @@ information regarding copyright ownership.
218218
<target>${java.version}</target>
219219
</configuration>
220220
</plugin>
221-
<plugin>
222-
<groupId>com.lewisd</groupId>
223-
<artifactId>lint-maven-plugin</artifactId>
224-
<version>0.0.11</version>
225-
<configuration>
226-
<failOnViolation>true</failOnViolation>
227-
<onlyRunRules>
228-
<rule>DuplicateDep</rule>
229-
<rule>RedundantPluginVersion</rule>
230-
<!-- Rules incompatible with Java 9
231-
<rule>VersionProp</rule>
232-
<rule>DotVersionProperty</rule> -->
233-
</onlyRunRules>
234-
</configuration>
235-
<executions>
236-
<execution>
237-
<id>pom-lint</id>
238-
<phase>validate</phase>
239-
<goals>
240-
<goal>check</goal>
241-
</goals>
242-
</execution>
243-
</executions>
244-
</plugin>
221+
245222
<plugin>
246223
<groupId>org.codehaus.mojo</groupId>
247224
<artifactId>exec-maven-plugin</artifactId>

nd4j-ndarray-examples/pom.xml

+1-24
Original file line numberDiff line numberDiff line change
@@ -152,30 +152,7 @@ information regarding copyright ownership.
152152
<target>${java.version}</target>
153153
</configuration>
154154
</plugin>
155-
<plugin>
156-
<groupId>com.lewisd</groupId>
157-
<artifactId>lint-maven-plugin</artifactId>
158-
<version>0.0.11</version>
159-
<configuration>
160-
<failOnViolation>true</failOnViolation>
161-
<onlyRunRules>
162-
<rule>DuplicateDep</rule>
163-
<rule>RedundantPluginVersion</rule>
164-
<!-- Rules incompatible with Java 9
165-
<rule>VersionProp</rule>
166-
<rule>DotVersionProperty</rule> -->
167-
</onlyRunRules>
168-
</configuration>
169-
<executions>
170-
<execution>
171-
<id>pom-lint</id>
172-
<phase>validate</phase>
173-
<goals>
174-
<goal>check</goal>
175-
</goals>
176-
</execution>
177-
</executions>
178-
</plugin>
155+
179156
</plugins>
180157
<pluginManagement>
181158
<plugins>

onnx-import-examples/pom.xml

+1-24
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,7 @@ information regarding copyright ownership.
174174
<target>${java.version}</target>
175175
</configuration>
176176
</plugin>
177-
<plugin>
178-
<groupId>com.lewisd</groupId>
179-
<artifactId>lint-maven-plugin</artifactId>
180-
<version>0.0.11</version>
181-
<configuration>
182-
<failOnViolation>true</failOnViolation>
183-
<onlyRunRules>
184-
<rule>DuplicateDep</rule>
185-
<rule>RedundantPluginVersion</rule>
186-
<!-- Rules incompatible with Java 9
187-
<rule>VersionProp</rule>
188-
<rule>DotVersionProperty</rule> -->
189-
</onlyRunRules>
190-
</configuration>
191-
<executions>
192-
<execution>
193-
<id>pom-lint</id>
194-
<phase>validate</phase>
195-
<goals>
196-
<goal>check</goal>
197-
</goals>
198-
</execution>
199-
</executions>
200-
</plugin>
177+
201178
<plugin>
202179
<groupId>org.codehaus.mojo</groupId>
203180
<artifactId>exec-maven-plugin</artifactId>

samediff-examples/pom.xml

+1-24
Original file line numberDiff line numberDiff line change
@@ -191,30 +191,7 @@ information regarding copyright ownership.
191191
<target>${java.version}</target>
192192
</configuration>
193193
</plugin>
194-
<plugin>
195-
<groupId>com.lewisd</groupId>
196-
<artifactId>lint-maven-plugin</artifactId>
197-
<version>0.0.11</version>
198-
<configuration>
199-
<failOnViolation>true</failOnViolation>
200-
<onlyRunRules>
201-
<rule>DuplicateDep</rule>
202-
<rule>RedundantPluginVersion</rule>
203-
<!-- Rules incompatible with Java 9
204-
<rule>VersionProp</rule>
205-
<rule>DotVersionProperty</rule> -->
206-
</onlyRunRules>
207-
</configuration>
208-
<executions>
209-
<execution>
210-
<id>pom-lint</id>
211-
<phase>validate</phase>
212-
<goals>
213-
<goal>check</goal>
214-
</goals>
215-
</execution>
216-
</executions>
217-
</plugin>
194+
218195
<plugin>
219196
<groupId>org.codehaus.mojo</groupId>
220197
<artifactId>exec-maven-plugin</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package org.nd4j.examples.samediff.quickstart.modeling;
2+
3+
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
4+
import org.nd4j.autodiff.listeners.impl.ScoreListener;
5+
import org.nd4j.autodiff.listeners.records.History;
6+
import org.nd4j.autodiff.samediff.SDVariable;
7+
import org.nd4j.autodiff.samediff.SameDiff;
8+
import org.nd4j.autodiff.samediff.TrainingConfig;
9+
import org.nd4j.evaluation.classification.Evaluation;
10+
import org.nd4j.evaluation.classification.Evaluation.Metric;
11+
import org.nd4j.linalg.api.buffer.DataType;
12+
import org.nd4j.linalg.api.ops.impl.layers.convolution.config.Conv2DConfig;
13+
import org.nd4j.linalg.api.ops.impl.layers.convolution.config.Pooling2DConfig;
14+
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
15+
import org.nd4j.linalg.learning.config.Adam;
16+
import org.nd4j.weightinit.impl.XavierInitScheme;
17+
18+
import java.util.List;
19+
20+
/**
21+
* Based on a great overview of transforms in pytorch:
22+
* https://medium.com/the-dl/transformers-from-scratch-in-pytorch-8777e346ca51
23+
*
24+
* Transformers are well known in many applications starting from NLP and
25+
* moving on to computer vision. This example shows how to implement transformers using samediff.
26+
*
27+
* Samediff supports both key ops for transforms: scaled dot production attention
28+
* <code>
29+
* SameDiff sd = SameDiff.create();
30+
* SDVariable queries = null;
31+
* SDVariable keys = null;
32+
* SDVariable values = null;
33+
* SDVariable mask = null;
34+
*
35+
* SDVariable sdVariable = sd.nn().dotProductAttention(queries, keys, values, mask, true);
36+
* </code>
37+
*
38+
*
39+
*
40+
* Samediff also supports multi-head attention:
41+
* <code>
42+
* SameDiff sd = SameDiff.create();
43+
* SDVariable queries = null;
44+
* SDVariable keys = null;
45+
* SDVariable values = null;
46+
* SDVariable mask = null;
47+
* SDVariable wq = null;
48+
* SDVariable wk = null;
49+
* SDVariable wv = null;
50+
* SDVariable wo = null;
51+
* SDVariable sdVariable1 = sd.nn().multiHeadDotProductAttention(queries, keys, values, wq, wk, wv, wo, mask, true);
52+
* </code>
53+
*
54+
* multi-head attention
55+
*
56+
*/
57+
public class TransformersExample {
58+
59+
public static SameDiff makeMNISTNet() {
60+
SameDiff sd = SameDiff.create();
61+
SDVariable queries = null;
62+
SDVariable keys = null;
63+
SDVariable values = null;
64+
SDVariable mask = null;
65+
SDVariable wq = null;
66+
SDVariable wk = null;
67+
SDVariable wv = null;
68+
SDVariable wo = null;
69+
SDVariable sdVariable1 = sd.nn().multiHeadDotProductAttention(queries, keys, values, wq, wk, wv, wo, mask, true);
70+
71+
SDVariable sdVariable = sd.nn().dotProductAttention(queries, keys, values, mask, true);
72+
//Properties for MNIST dataset:
73+
int nIn = 28 * 28;
74+
int nOut = 10;
75+
76+
//Create input and label variables
77+
SDVariable in = sd.placeHolder("input", DataType.FLOAT, -1, nIn); //Shape: [?, 784] - i.e., minibatch x 784 for MNIST
78+
SDVariable label = sd.placeHolder("label", DataType.FLOAT, -1, nOut); //Shape: [?, 10] - i.e., minibatch x 10 for MNIST
79+
80+
SDVariable reshaped = in.reshape(-1, 1, 28, 28);
81+
82+
Pooling2DConfig poolConfig = Pooling2DConfig.builder().kH(2).kW(2).sH(2).sW(2).build();
83+
84+
Conv2DConfig convConfig = Conv2DConfig.builder().kH(3).kW(3).build();
85+
86+
// layer 1: Conv2D with a 3x3 kernel and 4 output channels
87+
SDVariable w0 = sd.var("w0", new XavierInitScheme('c', 28 * 28, 26 * 26 * 4), DataType.FLOAT, 3, 3, 1, 4);
88+
SDVariable b0 = sd.zero("b0", 4);
89+
90+
SDVariable conv1 = sd.cnn().conv2d(reshaped, w0, b0, convConfig);
91+
92+
// layer 2: MaxPooling2D with a 2x2 kernel and stride, and ReLU activation
93+
SDVariable pool1 = sd.cnn().maxPooling2d(conv1, poolConfig);
94+
95+
SDVariable relu1 = sd.nn().relu(pool1, 0);
96+
97+
// layer 3: Conv2D with a 3x3 kernel and 8 output channels
98+
SDVariable w1 = sd.var("w1", new XavierInitScheme('c', 13 * 13 * 4, 11 * 11 * 8), DataType.FLOAT, 3, 3, 4, 8);
99+
SDVariable b1 = sd.zero("b1", 8);
100+
101+
SDVariable conv2 = sd.cnn().conv2d(relu1, w1, b1, convConfig);
102+
103+
// layer 4: MaxPooling2D with a 2x2 kernel and stride, and ReLU activation
104+
SDVariable pool2 = sd.cnn().maxPooling2d(conv2, poolConfig);
105+
106+
SDVariable relu2 = sd.nn().relu(pool2, 0);
107+
108+
SDVariable flat = relu2.reshape(-1, 5 * 5 * 8);
109+
110+
// layer 5: Output layer on flattened input
111+
SDVariable wOut = sd.var("wOut", new XavierInitScheme('c', 5 * 5 * 8, 10), DataType.FLOAT, 5 * 5 * 8, 10);
112+
SDVariable bOut = sd.zero("bOut", 10);
113+
114+
SDVariable z = sd.nn().linear("z", flat, wOut, bOut);
115+
116+
// softmax crossentropy loss function
117+
SDVariable out = sd.nn().softmax("out", z, 1);
118+
SDVariable loss = sd.loss().softmaxCrossEntropy("loss", label, out, null);
119+
120+
sd.setLossVariables(loss);
121+
122+
return sd;
123+
}
124+
125+
public static void main(String[] args) throws Exception {
126+
SameDiff sd = makeMNISTNet();
127+
128+
//Create and set the training configuration
129+
130+
Evaluation evaluation = new Evaluation();
131+
132+
double learningRate = 1e-3;
133+
TrainingConfig config = new TrainingConfig.Builder()
134+
.l2(1e-4) //L2 regularization
135+
.updater(new Adam(learningRate)) //Adam optimizer with specified learning rate
136+
.dataSetFeatureMapping("input") //DataSet features array should be associated with variable "input"
137+
.dataSetLabelMapping("label") //DataSet label array should be associated with variable "label"
138+
.trainEvaluation("out", 0, evaluation) // add a training evaluation
139+
.build();
140+
141+
// You can add validation evaluations as well, but they have some issues in beta5 and most likely won't work.
142+
// If you want to use them, use the SNAPSHOT build.
143+
144+
sd.setTrainingConfig(config);
145+
146+
// Adding a listener to the SameDiff instance is necessary because of a beta5 bug, and is not necessary in snapshots
147+
sd.addListeners(new ScoreListener(20));
148+
149+
int batchSize = 32;
150+
DataSetIterator trainData = new MnistDataSetIterator(batchSize, true, 12345);
151+
152+
//Perform training for 4 epochs
153+
int numEpochs = 4;
154+
History hist = sd.fit()
155+
.train(trainData, numEpochs)
156+
.exec();
157+
List<Double> acc = hist.trainingEval(Metric.ACCURACY);
158+
159+
System.out.println("Accuracy: " + acc);
160+
}
161+
}

tensorflow-keras-import-examples/pom.xml

+1-24
Original file line numberDiff line numberDiff line change
@@ -179,30 +179,7 @@ information regarding copyright ownership.
179179
<target>${java.version}</target>
180180
</configuration>
181181
</plugin>
182-
<plugin>
183-
<groupId>com.lewisd</groupId>
184-
<artifactId>lint-maven-plugin</artifactId>
185-
<version>0.0.11</version>
186-
<configuration>
187-
<failOnViolation>true</failOnViolation>
188-
<onlyRunRules>
189-
<rule>DuplicateDep</rule>
190-
<rule>RedundantPluginVersion</rule>
191-
<!-- Rules incompatible with Java 9
192-
<rule>VersionProp</rule>
193-
<rule>DotVersionProperty</rule> -->
194-
</onlyRunRules>
195-
</configuration>
196-
<executions>
197-
<execution>
198-
<id>pom-lint</id>
199-
<phase>validate</phase>
200-
<goals>
201-
<goal>check</goal>
202-
</goals>
203-
</execution>
204-
</executions>
205-
</plugin>
182+
206183
<plugin>
207184
<groupId>org.codehaus.mojo</groupId>
208185
<artifactId>exec-maven-plugin</artifactId>

0 commit comments

Comments
 (0)