Comments (13)
Can you show me the output of torch::install_torch(reinstall = TRUE)
? Also, I'assuming it doesnt fail if you run eg:
torch_randn(10)`?
from torch.
Sure!
torch::install_torch(reinstall = TRUE)
trying URL 'https://github.com/mlverse/libtorch-mac-m1/releases/download/LibTorch-for-R/libtorch-v2.0.1.zip'
Content type 'application/octet-stream' length 49631992 bytes (47.3 MB)
==================================================
downloaded 47.3 MB
trying URL 'https://torch-cdn.mlverse.org/binaries/refs/heads/main/latest/lantern-0.12.0.9000+cpu+arm64-Darwin.zip'
Content type 'application/zip' length 3602457 bytes (3.4 MB)
==================================================
downloaded 3.4 MB
✔ torch dependencies have been installed.
ℹ You must restart your session to use torch correctly.
Running a simple command such as torch_randn(10)
works.
torch::torch_randn(10)
torch_tensor
0.8753
0.9061
-1.8905
-0.2683
-0.4204
-0.3306
1.1119
0.0052
0.3246
-0.2530
[ CPUFloatType{10} ]
torch
also can access the M3 MPS. The following works.
x <- torch::torch_randn(10, 10)$to(device="mps")
y <- torch::torch_randn(10, 10)$to(device="mps")
torch::torch_mm(x, y)
The problems appear on the luz::fit()
function. We compiled the lantern
library from source, and tried to install it as follows.
# compiled lantern from source and configured env variables as follows
devtools::install(build = FALSE)
Running /Library/Frameworks/R.framework/Resources/bin/R CMD INSTALL \
/Users/gilberto/torch --install-tests
* installing to library ‘/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library’
* installing *source* package ‘torch’ ...
** using staged installation
CMAKE_FLAGS:
** libs
con compilatore C++: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
con SDK: ‘MacOSX14.4.sdk’
*** Building lantern!
mkdir -p ../build-lantern
cd ../build-lantern && cmake ../src/lantern -DCMAKE_INSTALL_PREFIX=/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/00LOCK-torch/00new/torch -DCMAKE_INSTALL_MESSAGE="LAZY" && cmake --build . --target install --config Release
### Lots of output...
-- Build files have been written to: /Users/gilberto/torch/build-lantern
## We then configured the env variables
Sys.setenv(LANTERN_URL="/Users/gilberto/torch/build-lantern")
Sys.setenv(TORCH_URL="/Users/gilberto/torch/build-lantern/libtorch")
## We then tried to install torch after this, but if falis
Either there is a problem with the lantern
code when using M3, or we have failed to install correctly after compiling from source.
from torch.
You might want to try setting the env var BUILD_LANTERN=1
then running remotes::install_github("mlverse/torch")
to build lantern from source. Although, I don't think lantern is the culprit here, as it's just a relatively thin wrapper around LibTorch. You might also need to build LibTorch from source.
from torch.
Also, have you tried installing pre-built binaries from with eg:
kind <- "cpu"
version <- "0.12.0.9000"
options(repos = c(
torch = sprintf("https://torch-cdn.mlverse.org/packages/%s/%s/", kind, version),
CRAN = "https://cloud.r-project.org" # or any other from which you want to install the other R dependencies.
))
install.packages("torch", type = "binary")
from torch.
Thanks! I have tried, but failed.
from torch.
Can you also try disabling MPS on luz, just so we can narrow a little more the problem.
You can do something like:
torch_model <- luz::fit(
torch_model,
data = list(train_x, train_y),
epochs = 100,
valid_data = list(test_x, test_y),
callbacks = list(luz::luz_callback_early_stopping(
patience = 20,
min_delta = 0.01
)),
verbose = TRUE,
accelerator = accelerator(cpu = TRUE)
)
from torch.
Works!!! Can we now make luz
work on MPS?
from torch.
I think we will need to figure out why torch fails on M3 + MPS for that model. I believe it's possible that you will need to build LibTorch from source to fix this issue.
from torch.
How do I build libtorch and liblantern from source?
from torch.
To build LibTorch from source, you can follow instructions the steps in this workflow file:
https://github.com/mlverse/libtorch-mac-m1/blob/main/.github/workflows/libtorch.yaml
Then copy the libtorch files into src/lantern/build and run load_all or dev tools::install with BUILD_LANTERN=1 set.
from torch.
Thanks!! I will try
from torch.
Dear @dfalbel we tried to build torch from source, but it did not work on Mac M3 chip. Looking at the pytorch github, other developers are having similar problems with the new M3 chip. Please see the following issue:
from torch.
Hello. I had a similar issue, but after I upgraded to macOS Sonoma 14.4.1 on a Mac M2. I posted on the Luz GitHub, but was happy to see some discussion here.
from torch.
Related Issues (20)
- Cuda 11.6 deprecated HOT 2
- Release torch 0.13.0
- `torch_triu_indices` and `torch_tril_indices` return 0-based index
- first and second order derivative of gamma samples HOT 1
- Unable to load pre-trained alexnet weights HOT 2
- Can't download lantern from https://torch-cdn.mlverse.org when install torch 0.13.0 in win11 HOT 4
- Number of dimensions of a tensor increases when indexing a dimension of length 1 with a one-dimension logical vector HOT 5
- Adding Regularization Term in NLS optimization
- `set_num_threads` on Linux does not seem to work
- Question about installation from pre-built binaries HOT 4
- Indexing a tensor by an R matrix should behave as if the matrix is a tensor
- Cannot install lantern dependencies on aarm64 architecture HOT 6
- GPU runtime + memory leakage HOT 1
- Backward pass fails on torch_max with the "inplace operation" error HOT 1
- GLIBCXX version error after installing 0.13.0 with CUDA support
- dataloader issure when use parallel HOT 3
- training in epoch ,error in sizes of tensors must match except in dimension1.expected size 1 but got size 28 for tensor number 2 in the list
- `torch_iinfo()` is failing for dtypes `torch_uint8()` and `torch_int8()`
- R session Aborted HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torch.