Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global toFree list from Python interop module #26493

Merged
merged 8 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 89 additions & 117 deletions modules/packages/Python.chpl

Large diffs are not rendered by default.

Empty file.
Empty file.
4 changes: 3 additions & 1 deletion test/library/packages/Python/examples/torch/myModel.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ proc main() {

// create the model
var model = myModelClass();
var input_tensor = tensor(owned Value, [[1.0,]], kwargs=["requires_grad" => true]);
var input_tensor = tensor(owned Value, [[1.0,]], kwargs=["requires_grad" => false]);
writeln("Input tensor: ", input_tensor);

// init model weights to 0.9
{
Expand All @@ -34,6 +35,7 @@ proc main() {
// compute the loss
var loss_fn = MSELoss();
var target = tensor(owned Value, [[2.0,]]);
writeln("Target: ", target);
var loss = loss_fn(owned ClassObject, pred, target);
loss.call(NoneType, "backward");

Expand Down
4 changes: 3 additions & 1 deletion test/library/packages/Python/examples/torch/mymodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def forward(self, x):
def main():
# create the model
model = MyModel()
input_tensor = torch.tensor([[1.0]], requires_grad=True)
input_tensor = torch.tensor([[1.0]], requires_grad=False)
print("Input tensor:", input_tensor)

# init model weights to 0.9
for p in model.parameters():
Expand All @@ -23,6 +24,7 @@ def main():
# compute the loss
loss_fn = torch.nn.MSELoss()
target = torch.tensor([[2.0]])
print("Target:", target)
loss = loss_fn(pred, target)
loss.backward()

Expand Down
Empty file.
14 changes: 13 additions & 1 deletion test/library/packages/Python/memleaks/lambdas.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ proc main() {
writeln(l(list(int), 1));
writeln(l(list(string), "hi"));

// this has a an extra lis
// this has an extra list
writeln(l(list(list(int)), [1, 2, 3]));

// chapelList([4,5,6])
var l2 = new Function(interp, "lambda x,y,z,: [x,y,z]");
// printing this out will cause a memleak, the __str__ method for list leaks
// e.g., 'print([[1,2,3])' in python leaks memory
l2(list(owned Value?), 1, "hi", [4, 5, 6]);
writeln("skipping potentially leaking print");


var l3 = new Function(interp, "lambda x,: x");
writeln(l3(list(int), [1,]));
writeln(l3(NoneType, [1,]));
}
3 changes: 3 additions & 0 deletions test/library/packages/Python/memleaks/lambdas.good
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[1, 1]
[hi, hi]
[[1, 2, 3], [1, 2, 3]]
skipping potentially leaking print
[1]
()
Loading