Posts

Showing posts from January, 2025

apollo graphql federation with hotchoc tutorial link

You can find a good tutorial about graphql federation here:- https://www.apollographql.com/tutorials/federation-hotchocolate/03-hot-chocolate

windows remote rdp resetting passsword shortcut

  Every now and then, we would to reset our password via rdp client. To do this we can just type   ctrl + alt + end Sometimes even googling can take a while to get this right! 

vLLM is running on UnspecifiedPlatform

Image
Bump into this error when trying to run vllm on my machine locally. If you have only CPU available, then you might bump into this error.  You can see if you have gpu support with the following code python -c 'import torch; print(torch.cuda.is_available( ))' vllm does provide a guide to setup for cpu environment here . I did run into pytorch, torchvision, torchaudio incompatiblity problem - if you have previous setup of pytorch or other project that might uses a different version in your laptop. Then you need to create a new python virtual environment. Simply re-installing torch might get you the latest version which does not meets the requirement. And if you try to  specified specific build version, you will still run into package download issues. Before you follow the instruction, please  1. clone the llvm repository .  cd into llvm and in the root, you should be able to run the script.  2. ensure you have install c/g++ 12  compiler (and above) - or simply...

python creating a virtual environment

This is quite a common thing to do when working with python. To setup your python virtual environment, you can start doing this.  python3 -m venv myllm To activate it  source myllm/bin/activate

c# with keyword record

Image
"with" keyword is kinda interesting as it allows deep copying. However, it can work with " record " or " struct " (directly). record can have class as its fields as we will see later. It is not possible to have class as shown in the code example here.  You will get error - "he receiver type 'MyRecord' is not a valid record type and is not a struct type". The following code shows we can copy mix record with class and then do a deep copy using "with" keyword.  var addr = new Address {     Addresss1 = "125 Don Buck" ,     Addresss2 = "Massey 0512 Auckland" ,     State = "Auckland" }; var addr2 = new Address {     Addresss1 = "125 Don Buck" ,     Addresss2 = "Massey 0512 Auckland" ,     State = "Auckland" }; var myrec = new MyRecord ( 1 , "jeremy" , addr ); var myrec2 = myrec with { id = 2 }; var myrec3 =     myrec with     {  ...

golang - slices, channel, map, pointers are references types - others are considered value type

When working with golang, it is important to remember that slices, channel, pointers and map are references types. The rest like string, integer are considered be value type. Example of code that demonstrate this here. You can see that although I am passing a struct into a function, it is a value type instead of reference type.  package main import "fmt" type Emplyee struct {     name string     id   int } func SetReferenceType ( value Emplyee ) {     value . id = 1000     value . name = "removed" } func SetValueType ( value int ) {     value = 1000 } func SetSlicesValue ( lst [] int ) {     lst [ 0 ] = 9     lst [ 1 ] = 10 } // reftype jeremy 10 // idx 10 // 9 // 10 // 3 func main () {     e := Emplyee { id : 10 , name : "jeremy" }     SetReferenceType ( e )     fmt . Println ( "reftype" , e . name , e . id )     // reftype jeremy 10   ...

golang generics and constraint interface

Golang has support for generic since 1.18. To see a simple example of how we can use it, check out the following codes:-  We declare generics right next to the function name declaration using [T number] as shown below:- package main import (     "fmt" ) type Number interface {     int | float32 | float64 } func PrintNumbers [ T Number ]( t [] T ) {     for _ , v := range t {         fmt . Println ( v )     } } func PrintValue [ T any ]( t [] T ) {     for _ , v := range t {         fmt . Println ( v )     } } func main () {     PrintValue ([] int { 1 , 2 , 3 , 4 })     PrintValue ([] string { "1" , "2" , "3" })     PrintNumbers ([] int { 1 , 2 , 3 , 4 })     // constraint are not satisfied here     //PrintNumbers([]string{"1", "2", "3"}) }   Then we have generics for struct - as you can see here type Bo...

golang goroutine with waitgroup

Waitgroup provides a simple and easy to use approach to managing go routines. A basic example can be shown here. package main import (     "fmt"     "sync" ) func worker ( id int , w * sync . WaitGroup ) {     defer w . Done ()     fmt . Printf ( "Worker: %d processing tasks \n " , id ) } func main () {     var wg sync . WaitGroup     const numTask = 2     // starting our worker     for i := 0 ; i < numTask ; i ++ {         wg . Add ( 1 )         fmt . Printf ( "firing task %d \n " , i )         go worker ( i , & wg )     }     wg . Wait ()     fmt . Println ( "Done" ) }

golang working with worker pool

In this code example, we are spawn up our worker, sends it some work and gets the results back. In the worker function, notice the we are using " result <- ( <- task * 100 ) " to get the value from task channel which is 0 or 1 and then multiple it by 100. package main import "fmt" func worker ( id int , task <- chan int , result chan <- int , errors chan <- error ) {     fmt . Printf ( "Worker: %d processing tasks \n " , id )     if id == 5 {         errors <- fmt . Errorf ( "worker %d failed to process task %d " , id , task )     }     // getting actula value from task and multiply with 100     result <- ( <- task * 100 ) } func main () {     const numTask = 2     tasks := make ( chan int , numTask )     results := make ( chan int , numTask )     errors := make ( chan error , numTask )     // starting our ...

golang - simple interface code

To work with golang interface, it really simple. A simple code could be as follows: package main import "fmt" type Vechical interface {     Accelerate ( r float32 ) bool } type Scotter struct { } func ( b Scotter ) Accelerate ( r float32 ) bool {     fmt . Println ( "Bike accelerating" )     return true } type Bike struct { } func ( b Bike ) Accelerate ( r float32 ) bool {     fmt . Println ( "Bike accelerating" )     return true } type Car struct { } func ( c Car ) Accelerate ( r float32 ) bool {     fmt . Println ( "Car accelerating" )     return true } func main () {     target := Scotter {} // Car{} or Bike{}     Test ( target ) } func Test ( v Vechical ) bool {     return v . Accelerate ( 10 ) }  

GCP - configure service account or other role

Goto IAM and admin -> IAM -> Click on Grant Access -> Under the Add principal -> select your service account created earlier or the one that you would like to configure.  Then under the role, select the role that you intended grant to this principal.  

golang function defer

This is an interesting way to do defer in golang. for i , v := range values {     go func ( i int , v string ) {         defer func () { done <- true }() // Always signal completion         if i == 1 {             return         }         fmt . Println ( v )     }( i , v ) }

creating ollama model from huggingface's model

Image
 First we will need to install hugging face cli and set the environment variable to optimize the download speed. pip install -U "huggingface_hub[cli]" pip install -U "huggingface_hub[hf_transfer]" HF_HUB_ENABLE_HF_TRANSFER=1 Next, we will download the model we wanted.  For example huggingface-cli download kepung/llama-fibo-gguf Then we note down the path of the model being transfered. Then create a Modelfile with the followings. Please change the path to the correct model that you have downloaded. FROM /root/.cache/huggingface/hub/ models--kepung--llama-fibo- gguf/snapshots/ 3b583d43ffab9421fbf272464c26ed 40dca13a15/unsloth.Q8_0.gguf Once you save it, ensure your llama is running. If not run ollama serve. Then in another command prompt, run  ollama create kepung/ollama-llama3-2 -f Modelfile  You should see the output from here.

hugging face - how to delete model from ui

Image
To delete the model, login to your account and then you will see the list of models and datasets belongs to you. Select the model you would like to delete and then scroll down further and you can see the deletion option

huggingface cli faster download

Improvement can be made to the downloads of model by installing the following package and setup pip install -U "huggingface_hub[cli]" pip install -U "huggingface_hub[hf_transfer]" Configure your environment variables HF_HUB_ENABLE_HF_TRANSFER=1  

terraform provider your segment does not match

This is a generic error and can happy for different resource that you're trying to provision. especially thoes that requires segment aka /subscriptions/123456/resourceGroup/my-rg pattern. In my case, trying to provision  azurerm_mssql_database_extended_auditing_policy  and i bump into this error:-   Error: parsing "/subscriptions/subscription/resourceGroups/your-rg/providers/Microsoft.Sql/servers/sqlserver": parsing the SqlDatabase ID: the number of segments didn't match * Segment 0 - this should be the literal value "subscriptions" │   * Segment 1 - this should be the UUID of the Azure Subscription │   * Segment 2 - this should be the literal value "resourceGroups" │   * Segment 3 - this should be the name of the Resource Group │   * Segment 4 - this should be the literal value "providers" │   * Segment 5 - this should be the name of the Resource Provider [for example 'Microsoft.Sql'] │   * Segment 6 - this should be the literal ...

getting your the ip of your node

 Try this: curl 'https://api.ipify.org?format=json' curl 'https://api.ipify.org?format=jso curl 'https://api.ipify.org?format=json'

ollama - how to push model

Image
First we need to configure your public key. Ollama website settings  Then goto ollama webiste, your user settings - https://ollama.com/settings/keys, add your public key here. It should be the same one in your laptop and this file is localted here  /usr/share/ollama/.ollama/id_ed25519.pub. The command the push model to your ollama account are here. First we need to figure out the model available currently in your computer. You can do that using the following command ollama list  Once you have done that, you can use this to rename mymodel to myuser/mymodel. Then push it to ollama. ollama cp mymodel myuser/mymodel ollama push myuser/mymodel Then you can see the following outputs 

github action reusable workflow

We can create templates for our github actions which is similar to Azure Devops templates.  To get started lets see how we can step a simple ones. Here is the code for github templates and this goes into probably a repository call template - for example - https://github.com/mitzenjeremywoo?tab=repositories Templates as shown here. The key thing here is workflow_call which is require together with its inputs paramters. name : build-dotnet on :   workflow_call :     # Introduced 'inputs' to define parameters that can be passed when calling this workflow     inputs :       project :         description : "Node version"         required : true         type : string jobs :   build-dotnet :     runs-on : ubuntu-latest     steps :       # check out       - name : checkout repo         uses : actions/checkout@v4 ...