Skip to content

Instantly share code, notes, and snippets.

View Atry's full-sized avatar
😷
Wear a Mask. Save Lives.

Yang, Bo Atry

😷
Wear a Mask. Save Lives.
View GitHub Profile
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[4], line 92
90 with torch.no_grad():
91 deepspeed_hybrid_engine.eval()
---> 92 print(deepspeed_hybrid_engine.generate(
93 torch.tensor([[1]], dtype=torch.int, device=deepspeed_hybrid_engine.device),
94 synced_gpus=True,
95 generation_config=GenerationConfig(max_new_tokens=20),
96 ))
@Atry
Atry / # hhvm-nightly - 2022-02-02_13-19-42.txt
Created February 2, 2022 21:33
hhvm-nightly (hhvm/hhvm/hhvm-nightly) on macOS 12 - Homebrew build logs
Homebrew build logs for hhvm/hhvm/hhvm-nightly on macOS 12
Build date: 2022-02-02 13:19:42

Akka HTTP DSL in continuation-passing style

Akka HTTP provides a powerful Scala DSL to create routes to handle HTTP requests. The DSL contains a set of Directives to extract information or manipulate requests or responses.

For example, the following cpsRoute accepts a GET request and extracts query parameters p1 and p2 with the help of get and parameters directive. If an HTTP client send a GET request to the URL /?p1=Hello&p2=World, it will receive the response of plain text Hello, World!.

import akka.http.scaladsl.server._, Directives._
def cpsRoute: Route = {
  get {

parameters("p1", "p2") { (p1, p2) =>

@Atry
Atry / CNN.sc
Last active November 13, 2017 09:30 — forked from TerrorJack/CNN.sc
CNN.sc
trait CNNs
extends com.thoughtworks.deeplearning.plugins.INDArrayLayers
with com.thoughtworks.deeplearning.plugins.ImplicitsSingleton
with com.thoughtworks.deeplearning.plugins.Training
with com.thoughtworks.deeplearning.plugins.Operators {
import org.nd4j.linalg.api.ndarray.INDArray
import org.nd4j.linalg.convolution.Convolution
import org.nd4j.linalg.util.ArrayUtil
import org.nd4j.linalg.factory.Nd4j
import org.nd4j.linalg.api.ops.impl.transforms.IsMax
@Atry
Atry / L2Regularization.sc
Last active July 27, 2017 07:40 — forked from TerrorJack/L2Regularization.sc
L2Regularization.sc
trait L2Regularization extends com.thoughtworks.deeplearning.plugins.INDArrayWeights {
import org.nd4j.linalg.api.ndarray.INDArray
val l2Regularization: Double
trait INDArrayOptimizerApi extends super.INDArrayOptimizerApi {
this: INDArrayOptimizer =>
abstract override def delta: INDArray = {
import org.nd4s.Implicits._
super.delta + weight.data * l2Regularization
@Atry
Atry / L1Regularization.sc
Last active July 31, 2017 04:09 — forked from TerrorJack/L1Regularization.sc
L1Regularization.sc
trait L1Regularization extends INDArrayWeights {
val l1Regularization: Double
trait INDArrayOptimizerApi extends super.INDArrayOptimizerApi {
this: INDArrayOptimizer =>
abstract override def delta: INDArray = {
import org.nd4s.Implicits._
import org.nd4j.linalg.ops.transforms.Transforms
super.delta + Transforms.sign(weight.data) * l1Regularization
}
@Atry
Atry / HListWitness.scala
Created March 3, 2017 07:15
A universal type class that includes all shapeless.HList operations
import shapeless._
import shapeless.ops.hlist.ZipWithIndex.Helper
import shapeless.poly._
import shapeless.ops.hlist.{
Length,
LiftAll,
Mapper,
ToCoproduct,
ToList,
@Atry
Atry / Output
Created October 17, 2016 01:17 — forked from fiadliel/Output
Example for sbt-api-mappings bug
$ sbt doc
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1G; support was removed in 8.0
[info] Loading global plugins from /home/xxx/.sbt/0.13/plugins
[info] Loading project definition from /home/xxx/sbt_api_mappings/project
[info] Set current project to sbt_api_mappings (in build file:/home/xxx/sbt_api_mappings/)
scala.MatchError: scala-compiler-2.12.0-RC1.jar (of class java.lang.String)
at com.thoughtworks.sbtApiMappings.ApiMappings$$anonfun$projectSettings$3$$anonfun$apply$2.apply(ApiMappings.scala:41)
at com.thoughtworks.sbtApiMappings.ApiMappings$$anonfun$projectSettings$3$$anonfun$apply$2.apply(ApiMappings.scala:39)
at scala.collection.TraversableLike$WithFilter$$anonfun$map$2.apply(TraversableLike.scala:722)
at scala.collection.immutable.List.foreach(List.scala:318)
scala> def test(size: Int, iterations: Int): Unit = {
| println(s"size of the list: $size")
| println(s"number of iterations: $iterations")
| val list = (0 until size).toList
| @volatile var dontOptimizeMe: Any = 0
| def bufferReverseIterator[A](list: List[A]) = {
| list.toBuffer.reverseIterator
| }
| def arrayReverseIterator[A](list: List[A]) = {
| val array = new Array[Any](list.size)
@Atry
Atry / AkkaHttpCorsSupport.scala
Created July 22, 2016 05:58 — forked from pcting/AkkaHttpCorsSupport.scala
Akka HTTP 1.0 CORS Support
import akka.http.scaladsl.model.HttpHeader
import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.model.HttpResponse
import akka.http.scaladsl.model.headers.`Access-Control-Allow-Credentials`
import akka.http.scaladsl.model.headers.`Access-Control-Allow-Methods`
import akka.http.scaladsl.model.headers.`Access-Control-Allow-Origin`
import akka.http.scaladsl.model.headers.Origin
import akka.http.scaladsl.server.Directive0
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.MethodRejection