Skip to content

Commit

Permalink
Add Scala Days video and update website
Browse files Browse the repository at this point in the history
- update sbt-typelevel plugin
- adapt to changes from update to Laika 1.0
- remove custom html templates and use css/js overrides instead
- add Apple Silicon docs
  • Loading branch information
sbrunk committed Feb 4, 2024
1 parent 2fff591 commit 3d3a646
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 232 deletions.
4 changes: 2 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export CUDA_CACHE_MAXSIZE=4294967296

Recent PyTorch versions provide a new backend based on Apple’s Metal Performance Shaders (MPS).
The MPS backend enables GPU-accelerated training on the M1/M2 architecture.
Right now, there's no ARM build of PyTorch in JavaCPP and MPS ist not enabled.
If you have an M1/M2 machine and want to help, check the umbrella [issue for macosx-aarch64 support](https://github.com/bytedeco/javacpp-presets/issues/1069).
While we have an ARM build of PyTorch in JavaCPP as of version `1.5.10`, MPS ist not enabled as the CI runners currently run on a macOS version that is too old.
If you want to help getting this to work, check out [the corresponding issue](https://github.com/bytedeco/javacpp-presets/issues/1464).
6 changes: 3 additions & 3 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ fork := true
There is one downside to this approach. Because `pytorch-platform` depends on the native libraries for all supported
platforms, it will download and cache **all** these libraries, no matter on which platform you actually are.

One way to avoid the overhead, is to explicitly depend on the native libraries for **your** platform instead of using
`pytorch-platform`.
One way to avoid the overhead is to explicitly depend on the native libraries for **your** platform instead of using
`pytorch-platform`. As of JavaCPP `1.5.10` the platform approach also doesn't work for `macosx-arm64` because the native dependencies are missing in the current version of `pytorch-platform` (should be fixed in the next release).

### Via classifier

This can be done by providing dependency classifiers specifically for your platform.
Currently supported are `linux-x86_64`, `macosx-x86_64` and `windows-x86_64`.
Currently supported are `linux-x86_64`, `macosx-x86_64`, `macosx-arm64` and `windows-x86_64`.

@:select(build-tool)

Expand Down
11 changes: 7 additions & 4 deletions examples/src/main/scala/ImageClassifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
//> using scala "3.3"
//> using repository "sonatype:snapshots"
//> using repository "sonatype-s01:snapshots"
//> using lib "dev.storch::vision:0.0-bbdc238-SNAPSHOT"
//> using lib "dev.storch::vision:0.0-2fff591-SNAPSHOT"
//> using lib "me.tongfei:progressbar:0.9.5"
//> using lib "com.github.alexarchambault::case-app:2.1.0-M24"
//> using lib "org.scala-lang.modules::scala-parallel-collections:1.0.4"
// replace with pytorch-platform-gpu if you have a CUDA capable GPU
//> using lib "org.bytedeco:pytorch-platform:2.0.1-1.5.10-SNAPSHOT"
//> using lib "org.bytedeco:pytorch-platform:2.1.2-1.5.10"
// enable for CUDA support
////> using lib "org.bytedeco:cuda-platform-redist:12.1-8.9-1.5.10-SNAPSHOT"
////> using lib "org.bytedeco:cuda-platform-redist:12.3-8.9-1.5.10"
// enable for native Apple Silicon support
// will not be needed with newer versions of pytorch-platform
////> using lib "org.bytedeco:pytorch:2.1.2-1.5.10,classifier=macosx-arm64"

import Commands.*
import ImageClassifier.{Prediction, predict, train}
Expand Down Expand Up @@ -80,7 +83,7 @@ object ImageClassifier extends CommandsEntryPoint:
extension (number: Double) def format: String = "%1.5f".format(number)

def train(options: TrainOptions): Unit =
val device = if torch.cuda.isAvailable then CUDA else CPU
val device = Device(DeviceType.MPS)
println(s"Using device: $device")

val datasetDir = os.Path(options.datasetDir, base = os.pwd)
Expand Down
57 changes: 42 additions & 15 deletions project/SiteSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,21 @@ import laika.helium.config.Favicon
import laika.helium.config.HeliumIcon
import laika.helium.config.IconLink
import laika.helium.config.ImageLink
import laika.rewrite.nav.{ChoiceConfig, Selections, SelectionConfig}
import laika.rewrite.link.{ApiLinks, LinkConfig}
import laika.config.{ApiLinks, LinkConfig, ChoiceConfig, SelectionConfig, Selections}

import laika.sbt.LaikaPlugin
import laika.theme.ThemeProvider

import java.net.URL
import laika.theme.config.{CrossOrigin, ScriptAttributes, StyleAttributes}

object StorchSitePlugin extends AutoPlugin {

override def requires = TypelevelSitePlugin
override def projectSettings = Seq(
tlSiteRelatedProjects := Seq(
"PyTorch" -> new URL("https://pytorch.org/"),
"JavaCPP" -> new URL("https://github.com/bytedeco/javacpp")
),
laikaConfig := LaikaConfig.defaults.withRawContent
.withConfigValue(
LinkConfig(apiLinks =
Seq(
// ApiLinks(baseUri = "http://localhost:4242/api/")
ApiLinks(baseUri = "https://storch.dev/api/")
)
)
LinkConfig.empty
// .addApiLinks(ApiLinks(baseUri = "http://localhost:4242/api/")
.addApiLinks(ApiLinks(baseUri = "https://storch.dev/api/"))
)
.withConfigValue(
Selections(
Expand All @@ -52,7 +43,7 @@ object StorchSitePlugin extends AutoPlugin {
).withSeparateEbooks
)
),
tlSiteHeliumConfig := Helium.defaults.site
tlSiteHelium := tlSiteHelium.value.site
.metadata(
title = Some("Storch"),
authors = developers.value.map(_.name),
Expand Down Expand Up @@ -90,6 +81,16 @@ object StorchSitePlugin extends AutoPlugin {
)
)
.site
.mainNavigation(
appendLinks = Seq(
ThemeNavigationSection(
"Related Projects",
TextLink.external("https://pytorch.org/", "PyTorch"),
TextLink.external("https://github.com/bytedeco/javacpp", "JavaCPP")
)
)
)
.site
.landingPage(
logo = Some(
Image.internal(Root / "img" / "storch.svg", height = Some(Length(300, LengthUnit.px)))
Expand Down Expand Up @@ -142,5 +143,31 @@ object StorchSitePlugin extends AutoPlugin {
)
)
)
.site
.internalCSS(Root / "css") // custom styles
// KaTeX
.site
.externalCSS(
url = "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css",
attributes = StyleAttributes.defaults
.withIntegrity("sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV")
.withCrossOrigin(CrossOrigin.Anonymous)
)
.site
.externalJS(
url = "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js",
attributes = ScriptAttributes.defaults.defer
.withIntegrity("sha384-XjKyOOlGwcjNTAIQHIpgOno0Hl1YQqzUOEleOLALmuqehneUG+vnGctmUb0ZY0l8")
.withCrossOrigin(CrossOrigin.Anonymous)
)
.site
.externalJS(
url = "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js",
attributes = ScriptAttributes.defaults.defer
.withIntegrity("sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05")
.withCrossOrigin(CrossOrigin.Anonymous)
)
.site
.internalJS(Root / "js" / "render-katex.js")
)
}
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("org.bytedeco" % "sbt-javacpp" % "1.17")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.7")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.2")
addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.22")
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.4.22")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.5")
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.6.5")
34 changes: 34 additions & 0 deletions site/src/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Adjust a few styles from landing-page.css */

#header {
padding-top: 20px;
}

#header-left h1, #header-left h2 {
color: var(--component-color);
line-height: 1;
margin-bottom: 5px;
}

#header-left h1 {
font-size: 40px;
}

#header-left h2 {
font-size: 22px;
margin-top: 0.7em;
}

.teaser h2 {
font-size: 20px;
margin-bottom: 0.25em;
margin-top: 0;
}

.teaser p {
font-size: 15px;
}

.teasers {
margin: 15px auto 0 auto;
}
121 changes: 0 additions & 121 deletions site/src/default.template.html

This file was deleted.

12 changes: 12 additions & 0 deletions site/src/js/render-katex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
// customised options
// • auto-render specific keys, e.g.:
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
],
// • rendering keys, e.g.:
throwOnError : false
});
});
13 changes: 13 additions & 0 deletions site/src/landing-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="teasers" style="padding-top: 0;">

<div class="teaser" style="min-width: 580px;">
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/ZoJanBS9kw8?si=sNssUCy4VFavgONu" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>

<div class="teaser" style="min-width: 660px; margin-top: -20px;">
<script id="asciicast-548330" src="https://asciinema.org/a/548330.js" async data-autoplay="true" data-speed="32" data-rows=24></script>
</div>

</div>

<p style="text-align: center; font-size: xx-small;"><a href="https://commons.wikimedia.org/wiki/File:Torch.svg">Torch</a> by Mailtoanton / CC BY-SA 3.0</p>
Loading

0 comments on commit 3d3a646

Please sign in to comment.