unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Pytorch Versions
@ 2024-05-13  3:00 Zain Jabbar
  2024-05-13 21:35 ` Richard Sent
  0 siblings, 1 reply; 2+ messages in thread
From: Zain Jabbar @ 2024-05-13  3:00 UTC (permalink / raw)
  To: help-guix

Aloha Guix Help,

After a few years I decided to really want to sit down and learn Guix
deeply. In this email, I wish to understand the difference between using
Guile Scheme to interact with Guix and using Bash to interact with Guix.

QUESTION: Why does Guile Scheme not find some package symbols that the
command line can?

BACKGROUND:
Firstly, the output of =guix describe=
```
zjabbar@tao ~/code/leetcode$ guix describe
Generation 628  May 12 2024 14:46:41    (current)
  guix 6ba29e0
    repository URL: https://git.savannah.gnu.org/git/guix.git
    branch: master
    commit: 6ba29e02108ed144da1234b4b5512ee03865dcf6
```

When I use =guix search python-pytorch= or use the Emacs Guix interface and
=M-x guix p n python-pytorch= I get three different versions of
=python-pytorch=: 1.13.1, 2.0.1, and 2.2.1.

They are all defined in =gnu/packages/machine-learning.scm=

Using =guix build python-pytorch= will build the latest version 2.2.1.

However, in Scheme,

```
(use-modules (gnu packages))
(specification->package "python-pytorch")
```

Returns the package 2.0.1. To my knowledge, we should be able to import the
Scheme module and use the symbol if it is exported directly or defined
using define-public. Hence, I expect the following,

```
(use-modules (gnu packages)
    (gnu packages machine-learning))

(specification->package "python-pytorch") ;; 2.2.1
python-pytorch ;; 1.13.1
python-pytorch2 ;; 2.2.1
python-pytorch-for-r-torch ;; 2.0.1
```

Instead I get,

```
(use-modules (gnu packages)
    (gnu packages machine-learning))

(specification->package "python-pytorch") ;; 2.0.1
python-pytorch ;; 1.13.1
python-pytorch2 ;; Unbound variable: python-pytorch2
python-pytorch-for-r-torch ;; 2.0.1
```

This means that the following code does not work because Guile does not
find version 2.2.1,

```
(use-modules (gnu packages)
    (guix transformations))

((options->transformation '((with-input . "python-pytorch@1.13.1
=python-pytorch@2.2.1")))
 (specification->package "python-torchvision"))
```

The following does also does not work,

```
(use-modules (gnu packages)
    (guix packages))

((package-input-rewriting `((,python-pytorch . ,python-pytorch2)))
 (specification->package "python-torchvision"))
```


-- 
Mahalo,
Zain Jabbar

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Pytorch Versions
  2024-05-13  3:00 Pytorch Versions Zain Jabbar
@ 2024-05-13 21:35 ` Richard Sent
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Sent @ 2024-05-13 21:35 UTC (permalink / raw)
  To: Zain Jabbar; +Cc: help-guix

Zain Jabbar <zaijab2000@gmail.com> writes:

> QUESTION: Why does Guile Scheme not find some package symbols that the
> command line can?
> 
> ...
> 
> ```
> (use-modules (gnu packages)
>     (gnu packages machine-learning))
>
> (specification->package "python-pytorch") ;; 2.2.1
> python-pytorch ;; 1.13.1
> python-pytorch2 ;; 2.2.1
> python-pytorch-for-r-torch ;; 2.0.1
> ```
>
>
> Instead I get,
>
> ```
> (use-modules (gnu packages)
>     (gnu packages machine-learning))
>
> (specification->package "python-pytorch") ;; 2.0.1
> python-pytorch ;; 1.13.1
> python-pytorch2 ;; Unbound variable: python-pytorch2
> python-pytorch-for-r-torch ;; 2.0.1
> ```

I found that your code did behave as expected when using $ guix repl
instead of $ guile.

--8<---------------cut here---------------start------------->8---
~ $ guix time-machine -q -- repl
GNU Guile 3.0.9
Copyright (C) 1995-2023 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guix-user)> (use-modules (gnu packages) (gnu packages machine-learning))
scheme@(guix-user)> (specification->package "python-pytorch")
$1 = #<package python-pytorch@2.2.1 gnu/packages/machine-learning.scm:4250 7fa2f439cf20>
scheme@(guix-user)> python-pytorch
$2 = #<package python-pytorch@1.13.1 gnu/packages/machine-learning.scm:4102 7fa2f4395000>
scheme@(guix-user)> python-pytorch2
$3 = #<package python-pytorch@2.2.1 gnu/packages/machine-learning.scm:4250 7fa2f439cf20>
scheme@(guix-user)> python-pytorch-for-r-torch
$4 = #<package python-pytorch@2.0.1 gnu/packages/machine-learning.scm:4305 7fa2f439ce70>
scheme@(guix-user)> 
--8<---------------cut here---------------end--------------->8---

vs.

--8<---------------cut here---------------start------------->8---
~ $ guile
GNU Guile 3.0.9
Copyright (C) 1995-2023 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (use-modules (gnu packages) (gnu packages machine-learning))
scheme@(guile-user)> python-pytorch
$1 = #<package python-pytorch@1.13.1 gnu/packages/machine-learning.scm:4102 7f16595b7370>
scheme@(guile-user)> python-pytorch2
;;; <stdin>:3:0: warning: possibly unbound variable `python-pytorch2'
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
error: python-pytorch2: unbound variable

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
--8<---------------cut here---------------end--------------->8---

My guess is it has to do with the different %load-path values in guix
repl vs guile. From the manual:

> Compared to just launching the ‘guile’ command, ‘guix repl’ guarantees
> that all the Guix modules and all its dependencies are available in
> the search path.

Comparing the load paths (guix-user = guix repl, guile-user = guile):

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> %load-path
$1 =
("/gnu/store/81h1vz3v1naagi1hzb2jgz4d7wsa02km-guix-module-union/share/guile/site/3.0"
;; snip at first entry containing gnu/packages/machine-learning.scm
)
scheme@(guix-user)> 

scheme@(guile-user)> %load-path
$1 = ("/home/richard/.guix-home/profile/share/guile/site/3.0"
"/run/current-system/profile/share/guile/site/3.0"
;; another snip
)
--8<---------------cut here---------------end--------------->8---

Indeed, if we then go through those load path entries looking for the
first file matching (gnu packages machine-learning), I find that guix
repl matches a machine-learning.scm file that contains python-pytorch2.
Guile's repl contains a (presumably) older version of
machine-learning.scm that does NOT contain python-pytorch2, only
python-pytorch.

The matching file for guile is in
/run/current-system/profile/share/guile/site/3.0. I suspect that means
Guile is finding a version of Guix installed via the Guix package (see
(gnu packages package-management)). Meanwhile, guix repl is using the
same version of Guix you find when running $ guix describe.

We can confirm this via:

--8<---------------cut here---------------start------------->8---
~ $ guix shell -C guix guile 
The following derivation will be built:
  /gnu/store/3gv2vzpypxf975a55pnkjgwjalda13j8-profile.drv

building CA certificate bundle...
listing Emacs sub-directories...
building fonts directory...
building directory of Info manuals...
building profile with 2 packages...
richard@gibraltar ~ [env]$ guile
GNU Guile 3.0.9
Copyright (C) 1995-2023 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> ,use (gnu packages machine-learning)
scheme@(guile-user)> python-pytorch
$1 = #<package python-pytorch@1.13.1 gnu/packages/machine-learning.scm:4102 7fce640359a0>
scheme@(guile-user)> python-pytorch2
;;; <stdin>:3:0: warning: possibly unbound variable `python-pytorch2'
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
error: python-pytorch2: unbound variable

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
--8<---------------cut here---------------end--------------->8---

If this didn't make sense, don't worry. I barely followed what I said
and I very easily might have said something wrong.

Generally speaking use $ guix repl if you want to ensure you're loading
the same modules as $ guix describe.

-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-13 21:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-13  3:00 Pytorch Versions Zain Jabbar
2024-05-13 21:35 ` Richard Sent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).