Skip to content

Commit

Permalink
Merge pull request #17 from Iainmon/detach-semantics
Browse files Browse the repository at this point in the history
Add scalar-tensor binary operations
Improve tensor printing
Add computational graph AST display
Add GeLU activation function
Improve tensor dtype consistency for saving and loading with chai.py
Fix broken VGG example and README
Add tensor meta definitions when saving tensors from python.
  • Loading branch information
Iainmon authored Jan 18, 2025
2 parents 8ddecf8 + e7a1802 commit 55946fd
Show file tree
Hide file tree
Showing 63 changed files with 760,958 additions and 158 deletions.
28 changes: 28 additions & 0 deletions detach_tensor_test.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use Tensor;

use Autograd;


var a: tensor(2,real) = tensor.arange(3,3);

writeln(a);


var b: tensor(2,real) = tensor.arange(3,3) * -0.1;
writeln(b);

var c = a + b + b + b;

writeln(c);

var d = c;

c.eraseHistory();

writeln(d.meta.showGraph());
writeln(c.meta.showGraph());

// writeln((a + b + c).meta.showGraph(indent=true));


writeln(b.gelu());
2 changes: 1 addition & 1 deletion examples/vgg/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.chdata
*.json
# *.json
__pycache__/
7 changes: 5 additions & 2 deletions examples/vgg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ Run `python3 dump_weights.py` to download the model and prep it for Chapel.

## Processing an image

Run `python3 process_image.py <path to image>` to process an image. The image will be resized to 224x224 and normalized to the imagenet mean and standard deviation. The output will be saved in a convenient format for ChAI in `imgs/`
Run `python3 process_img.py <path to image>` to process an image. The image will be resized to 224x224 and normalized to the imagenet mean and standard deviation. The output will be saved in a convenient format for ChAI in `imgs/`

## Running the model

Compile the Chapel code with `chpl --fast test.chpl -M ../../src -M ../../lib -o vgg` and run it with `./vgg <path to image>`. The output will be the top 5 classes and their probabilities.
Compile the Chapel code with `chpl --fast test.chpl -M ../../src -M ../../lib -o vgg` and run it with `./vgg <path to image>.chdata`. The output will be the top 5 classes and their probabilities.

## Running the python model

Run `python3 test.py <path to image>` to run the model in python. The output will be the top 5 classes and their probabilities.

#### Compare with `python3 run_vgg.py imgs/frog.jpg` and `./vgg imgs/frog.chdata`

1 change: 1 addition & 0 deletions examples/vgg/chai.py
3 changes: 2 additions & 1 deletion examples/vgg/dump_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
os.makedirs('models/vgg16', exist_ok=True)
model.chai_dump('models/vgg16','vgg16', with_json=False, verbose=True)


# print(model.state_dict().keys())
# print([(n,w.dtype) for (n,w) in model.state_dict().items()])
Loading

0 comments on commit 55946fd

Please sign in to comment.