Skip to content

Commit

Permalink
chore: fmt (#63)
Browse files Browse the repository at this point in the history
* chore: fmt

* chore: bump version
  • Loading branch information
load1n9 authored Sep 11, 2024
1 parent ee217d0 commit a3d719e
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 222 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
rustc --version
cargo --version
cargo build --release -p netsaur
deno run -Ar jsr:@deno/[email protected].1 -p netsaur --out src/backends/wasm/lib
deno run -Ar jsr:@deno/[email protected].1 -p netsaur-tokenizers --out tokenizers/lib
deno run -Ar jsr:@deno/[email protected].2 -p netsaur --out src/backends/wasm/lib
deno run -Ar jsr:@deno/[email protected].2 -p netsaur-tokenizers --out tokenizers/lib
- name: Release
uses: softprops/action-gh-release@master
env:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
package.version = "0.4.0"
package.version = "0.4.1"
members = ["crates/*"]
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@denosaurs/netsaur",
"version": "0.4.0",
"version": "0.4.1",
"exports": {
".": "./mod.ts",
"./web": "./web.ts",
Expand Down
7 changes: 7 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/src/backends/cpu/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const options: FetchOptions = {
name: "netsaur",
url: new URL(import.meta.url).protocol !== "file:"
? new URL(
"https://github.com/denosaurs/netsaur/releases/download/0.4.0/",
"https://github.com/denosaurs/netsaur/releases/download/0.4.1/",
import.meta.url,
)
: "./target/release/",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/backends/gpu/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const options: FetchOptions = {
name: "netsaur_gpu",
url: new URL(import.meta.url).protocol !== "file:"
? new URL(
"https://github.com/denosaurs/netsaur/releases/download/0.3.2-patch/",
"https://github.com/denosaurs/netsaur/releases/download/0.4.1/",
import.meta.url,
)
: "./target/release/",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/backends/wasm/lib/netsaur.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const imports = {
__wbindgen_object_drop_ref: function (arg0) {
takeObject(arg0);
},
__wbg_log_023d7669e382bddf: function (arg0, arg1) {
__wbg_log_6f7dfa87fad40a57: function (arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
},
__wbindgen_number_new: function (arg0) {
Expand Down
Binary file modified packages/core/src/backends/wasm/lib/netsaur_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/core/src/backends/wasm/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class WASMInstance {
await instantiate({
url: new URL(import.meta.url).protocol !== "file:"
? new URL(
"https://github.com/denosaurs/netsaur/releases/download/0.3.2-patch/netsaur_bg.wasm",
"https://github.com/denosaurs/netsaur/releases/download/0.4.1/netsaur_bg.wasm",
import.meta.url,
)
: undefined,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/backends/wasm/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import type { Rank, Shape } from "../../core/api/shape.ts";
/**
* Train Options Interface.
*/
export type TrainOptions = {
export interface TrainOptions {
datasets: number;
inputShape: Shape<Rank>;
outputShape: Shape<Rank>;
epochs: number;
batches: number;
rate: number;
};
}

/**
* Predict Options Interface.
*/
export type PredictOptions = {
export interface PredictOptions {
inputShape: Shape<Rank>;
outputShape: Shape<Rank>;
};
}
16 changes: 8 additions & 8 deletions packages/core/src/core/api/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type Layer =
/**
* The configuration for a dense layer.
*/
export type DenseLayerConfig = {
export interface DenseLayerConfig {
/**
* The type of initialization to use.
*/
Expand All @@ -46,7 +46,7 @@ export type DenseLayerConfig = {
/**
* The configuration for a dropout layer.
*/
export type DropoutLayerConfig = {
export interface DropoutLayerConfig {
/**
* probability of dropping out a value.
*/
Expand All @@ -61,7 +61,7 @@ export type DropoutLayerConfig = {
/**
* The configuration for an activation layer.
*/
export type ActivationLayerConfig = {
export interface ActivationLayerConfig {
/**
* The activation function to use.
*/
Expand All @@ -71,7 +71,7 @@ export type ActivationLayerConfig = {
/**
* The configuration for a convolutional layer.
*/
export type Conv2DLayerConfig = {
export interface Conv2DLayerConfig {
/**
* The type of initialization to use.
*/
Expand Down Expand Up @@ -111,7 +111,7 @@ export type Conv2DLayerConfig = {
/**
* The configuration for a convolutional transpose layer.
*/
export type ConvTranspose2DLayerConfig = {
export interface ConvTranspose2DLayerConfig {
/**
* The type of initialization to use.
*/
Expand Down Expand Up @@ -158,7 +158,7 @@ export enum PoolMode {
/**
* The configuration for a pooling layer.
*/
export type Pool2DLayerConfig = {
export interface Pool2DLayerConfig {
/**
* The optional strides to use.
*/
Expand All @@ -173,7 +173,7 @@ export type Pool2DLayerConfig = {
/**
* The configuration for a flatten layer.
*/
export type FlattenLayerConfig = {
export interface FlattenLayerConfig {
/**
* The size of the layer.
*/
Expand All @@ -183,7 +183,7 @@ export type FlattenLayerConfig = {
/**
* The configuration for a batch normalization layer.
*/
export type BatchNormLayerConfig = {
export interface BatchNormLayerConfig {
/**
* The momentum to use for the batch normalization.
* Defaults to 0.99.
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/core/api/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ export type Optimizer =
| { type: OptimizerType.Nadam; config: AdamOptimizerConfig }
| { type: OptimizerType.RMSProp; config: RMSPropOptimizerConfig };

export type AdamOptimizerConfig = {
export interface AdamOptimizerConfig {
beta1?: number;
beta2?: number;
epsilon?: number;
};
}

export type RMSPropOptimizerConfig = {
export interface RMSPropOptimizerConfig {
decayRate?: number;
epsilon?: number;
};
}

export function SGDOptimizer(): Optimizer {
return { type: OptimizerType.SGD };
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/core/api/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export type Scheduler =
}
| { type: SchedulerType.OneCycle; config: OneCycleSchedulerConfig };

export type DecaySchedulerConfig = {
export interface DecaySchedulerConfig {
rate?: number;
step_size?: number;
};
}

export type OneCycleSchedulerConfig = {
export interface OneCycleSchedulerConfig {
max_rate?: number;
step_size?: number;
};
}

export function NoScheduler(): Scheduler {
return { type: SchedulerType.None };
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/core/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export interface BackendInstance {
export interface BackendLoader {
/**
* Whether the backend is supported.
*
* ```ts
* import { WASM } from "https://deno.land/x/netsaur/mod.ts";
*
* console.log(WASM.isSupported());
* ```
*/
isSupported(): boolean;

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/core/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import { SGDOptimizer } from "./api/optimizer.ts";
*/
export class Sequential implements NeuralNetwork {
backend!: Backend;
config: NetworkConfig;

/**
* Create a Sequential Neural Network.
*/
constructor(public config: NetworkConfig) {
constructor(config: NetworkConfig) {
this.config = config;
this.config.cost = this.config.cost || Cost.MSE;
this.config.optimizer = this.config.optimizer || SGDOptimizer();
this.config.scheduler = this.config.scheduler || {
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/core/tensor/tensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
} from "../api/shape.ts";
import { inferShape, length } from "./util.ts";

export type TensorLike<R extends Rank> = {
export interface TensorLike<R extends Rank> {
shape: Shape<R>;
data: Float32Array;
};
Expand All @@ -35,13 +35,20 @@ export class Tensor<R extends Rank> {

/**
* Creates an empty tensor.
* ```ts
* Tensor.zeros([2, 2]);
* ```
*/
static zeroes<R extends Rank>(shape: Shape<R>): Tensor<R> {
return new Tensor(new Float32Array(length(shape)), shape);
}

/**
* Serialise a tensor into JSON.
*
* ```ts
* tensor([1, 2, 3, 4], [2, 2]).toJSON();
* ```
*/
toJSON(): { data: number[]; shape: Shape<R> } {
const data = new Array(this.data.length).fill(1);
Expand Down
25 changes: 21 additions & 4 deletions packages/core/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export interface Backend {
* The train method is a function that trains a neural network using a set of training data.
* It takes in an array of DataSet objects, the number of epochs to train for, and the learning rate.
* The method modifies the weights and biases of the network to minimize the cost function and improve its accuracy on the training data.
*
* ```ts
* net.train(datasets, 100, 10, 0.01);
* ```
*/
train(
datasets: DataSet[],
Expand All @@ -24,6 +28,11 @@ export interface Backend {
* The predict method is a function that takes in a Tensor object
* representing the input to the neural network and returns a Promise that resolves to a Tensor object representing the output of the network.
* This method is used to make predictions on new data after the network has been trained.
*
* ```ts
* const input = new Tensor([1, 2, 3, 4]);
* const output = await net.predict(input);
* ```
*/
predict(
input: Tensor<Rank>,
Expand All @@ -34,20 +43,28 @@ export interface Backend {
/**
* The save method is a function that saves the network to a Uint8Array.
* This method is used to save the network after it has been trained.
*
* ```ts
* const buffer = net.save();
* ```
*/
save(): Uint8Array;

/**
* The saveFile method is a function that takes in a string representing the path to a file and saves the network to that file.
* This method is used to save the network after it has been trained.
*
* ```ts
* net.saveFile("model.bin");
* ```
*/
saveFile(path: string): void;
}

/**
* NetworkConfig represents the configuration of a neural network.
*/
export type NetworkConfig = {
export interface NetworkConfig {
/**
* Input size of the neural network.
*/
Expand Down Expand Up @@ -87,7 +104,7 @@ export type NetworkConfig = {
* Number of disappointing iterations to allow before early stopping
*/
patience?: number;
};
}

/**
* Activation functions are used to transform the output of a layer into a new output.
Expand Down Expand Up @@ -195,10 +212,10 @@ export enum SchedulerType {
/**
* DataSet is a container for training data.
*/
export type DataSet = {
export interface DataSet {
inputs: Tensor<Rank>;
outputs: Tensor<Rank>;
};
}

export enum LayerType {
Activation = "activation",
Expand Down
Binary file modified packages/tokenizers/lib/netsaur_tokenizers_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/tokenizers/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function init(): Promise<void> {
await instantiate({
url: new URL(import.meta.url).protocol !== "file:"
? new URL(
"https://github.com/denosaurs/netsaur/releases/download/0.3.2-patch/netsaur_tokenizers_bg.wasm",
"https://github.com/denosaurs/netsaur/releases/download/0.4.1/netsaur_tokenizers_bg.wasm",
import.meta.url,
)
: undefined,
Expand Down
Loading

0 comments on commit a3d719e

Please sign in to comment.