<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Enrico Rampazzo on Medium]]></title>
        <description><![CDATA[Stories by Enrico Rampazzo on Medium]]></description>
        <link>https://medium.com/@Enrico_Rampazzo?source=rss-59c7fb7188d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Xz5VycnuFts8DZkNZiwj7g.jpeg</url>
            <title>Stories by Enrico Rampazzo on Medium</title>
            <link>https://medium.com/@Enrico_Rampazzo?source=rss-59c7fb7188d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 20:02:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Enrico_Rampazzo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[5 Challenges Solved by Graph Databases That No One Talks About]]></title>
            <link>https://medium.com/knowledge-nexus-ai/5-challenges-solved-by-graph-databases-that-no-one-talks-about-a01aeab60210?source=rss-59c7fb7188d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a01aeab60210</guid>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[cypher]]></category>
            <category><![CDATA[graph-database]]></category>
            <dc:creator><![CDATA[Enrico Rampazzo]]></dc:creator>
            <pubDate>Tue, 29 Oct 2024 16:26:24 GMT</pubDate>
            <atom:updated>2024-10-29T20:08:21.777Z</atom:updated>
            <content:encoded><![CDATA[<p>Should you consider using a Graph database for your next project? I think so, and in this article, I am going to articulate why.</p><h3>1. Graph databases are relational, for real!</h3><p>When you start a new project, one of the first challenges is to define the data you will be working on and its relationships. Now, despite their name, <em>relational databases</em> (RD) are not very good at representing relations. There’s no way to represent a relationship, because RDs only have tables and columns: when two tables are related, one of the tables has a column that contains the ids from another table, but there’s no concept of relationship. This is why when you want to join two sql tables you end up writing something along the lines of</p><pre>SELECT * FROM CUSTOMER, ORDER<br>WHERE CUSTOMER.ID = ORDER.CUSTOMER_ID<br>Using Cypher (the SQL equivalent for Graph databases) you would write<br>MATCH (c:Customer)-[r:HAS_ORDER]-&gt;(o:Order) RETURN c, r, o</pre><p>Now, I might be biased, but I find the second one much more intuitive once you know that MATCH is the equivalent of SELECT, because the relation between the entities is clearly stated in the query, and not implied by the fact that two columns in two different tables have the same value.</p><h3>2. Finding your way through the maze</h3><p>It is said that the foundation of graph theory came from the solution that Euler gave of the Seven Bridges of Königsberg problem: Konigsberg (now Kaliningrad) is a city that comprises an island, connected with the mainland by 7 bridges. His intent was to find a path that allows you to visit the city by passing each bridge only once. He abstracted the problem to vertexes (or nodes) connected by edges. This is interesting, because abstracting even more, a lot of processes can follow this same paradigm: imagine customer support, where each answer from the customer opens (or closes) new “bridges” that we can traverse towards the solution.</p><p>For example, internet troubleshooting can be represented as a graph where the nodes are the actions taken and the paths are the result of such actions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*yQeazE46owi7svcl1jCduA.png" /></figure><p>Because routing algorithms are often baked in graph databases, you can show all the possible paths that allow you to start from a node (in this case, the node Start) and arrive to a node where the internet is restored. It would be difficult to say the least to model this without a graph.</p><h3>3. Context is everything: improving RAG with a graph database</h3><p>Retrieval Augmented Generation allows a large language model to use data outside its training data by injecting it together with user question. For example, let’s say I want to know today’s gold prices: my prompt would be something along the lines of “What’s today’s gold price in Dubai?”. Obviously, the model cannot find this information in its training data, but let’s say there’s an API that can retrieve the price of gold and inject it in the prompt, so that it becomes:</p><p>“Given that today’s gold price in Dubai is 100 $ per gram, what’s today’s gold price in Dubai?”</p><p>Now the model has the data to answer the question, and that data can be easily updated.</p><p>If, however, you have a large collection of documents that might be relevant to a question, you cannot blindly inject all of them together with the prompt, because there’s a hard limit on how long a prompt can be: this is called <em>context window</em>, and each model has its own limit.</p><p>One way to determine which documents to include is to use <em>cosine similarity</em>, which measures the semantic similarity between the user question and the documents in your database. Using a graph database, you could inject all the documents that are adjacent to the one deemed relevant by the cosine similarity search thus enriching the response generated by the LLM. Let’s say cosine similarity retrieves document 1, which mentions document 2 and is mentioned by document 3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2dGgOeA632IREo-F1hWQA.png" /></figure><p>Using this Cypher query, you could get all the document adjacent to document 1, so documents 2 and 3, and inject them in the LLM context:</p><pre>MATCH (d:Document {id:1}) - {1}(n) RETURN n</pre><p>MATCH (d:Document {id:1}) references the node labelled as ‘Document’ where the property id is equal to 1</p><p>— {1}(n) finds all the nodes within 1 hop from document d, if you wanted to also get documents with id 4 and 5 you would need to change it to — {2}(n)</p><p>Because this relationship in <em>undirected</em>, it would both nodes that node d <em>connects to</em> and nodes that connects to node d</p><p>If you wanted to get only outgoing relationships from node d you would need to write</p><p>→{1}(n), which would only return node 2</p><p>Again, a graph database makes this trivial because relationships exist alongside the nodes.</p><h3>4. Growing your domain model without growing pains</h3><p>One of the downsides of representing your domain data with a relational database is that mistakes or simply changing requirements can be painful.</p><p>Let’s say you are modeling books and authors, with the assumption that a book can only have one author, and that one author can write many books.</p><p>You would end up with the table Book having an author_id column representing who wrote said book.</p><p>What happens, however, if a book has more than one author? Because the relation now becomes many-to-many, you have to create a new join table, which can be costly if your database is shared between many applications: your table structure changes (the Book table no longer has the foreign key column, a new table is added), which means that your queries also change, and you need to create new foreign key indexes.</p><p>In a graph database, all you need to do is create a new relation between the Book node and the Author nodes that represent the additional authors: the graph hasn’t really changed, so pre-existing queries would still work, although of course now they would return possibly more than one author, so your code might still need to slightly change, but nothing comparable to the pain you would go through with a SQL database:</p><pre>MATCH (a:Author)-[:WROTE]-&gt;(b:Book {id:$id}) RETURN a</pre><p>will return the authors of the book with id $id regardless of how many of them there are.</p><h3>5. Constraints, but only when you need them</h3><p>Graph databases are called schema-less, meaning that how an entity is labeled does not dictate the kind of properties it must have, unlike a SQL table, that defines columns and their types.</p><p>You can still enforce schemas if you want to, though: for example this Cypher statement will enforce all nodes labeled as :Document to have a field called id with an unique value</p><pre>CREATE CONSTRAINT unique_idx FOR (d:Document) REQUIRE n.id IS UNIQUE</pre><p>In this way you can still have a schema, but only when and if it makes sense to do so.</p><h3>6. Conclusions</h3><p>To summarize, I think graph databases are a good choice for highly interconnected data, they provide a good structure to model complex domains and problems, and they are ready to work in conjunction with LLMs for RAG applications. Last but not least, they can work well with both structured and unstructured data by declaring constraints but only when needed</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a01aeab60210" width="1" height="1" alt=""><hr><p><a href="https://medium.com/knowledge-nexus-ai/5-challenges-solved-by-graph-databases-that-no-one-talks-about-a01aeab60210">5 Challenges Solved by Graph Databases That No One Talks About</a> was originally published in <a href="https://medium.com/knowledge-nexus-ai">Knowledge-Nexus-AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I learned from running Llama-3 locally on an ultralight laptop without a GPU]]></title>
            <link>https://medium.com/@Enrico_Rampazzo/what-i-learned-from-running-llama-3-locally-on-an-ultralight-laptop-without-a-gpu-3dd4236eb547?source=rss-59c7fb7188d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dd4236eb547</guid>
            <category><![CDATA[local-llm]]></category>
            <dc:creator><![CDATA[Enrico Rampazzo]]></dc:creator>
            <pubDate>Sun, 04 Aug 2024 14:14:34 GMT</pubDate>
            <atom:updated>2024-08-07T10:01:46.361Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Promising, but not yet ready for prime time</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*80FKXYyZzDAhtQNbpicIew.jpeg" /></figure><p>So, I decided to try freelancing, and my wife said I need to impress prospective customers with a proper laptop, so I got a Thinkpad Carbon X1 12th Generation: it’s unbelievably light, has 32 GB of RAM and excellent battery life.</p><p>It also has an NPU, short for a neural processing unit, i.e. a processor optimized to do matrix multiplication, which underpins deep learning training and inference. That got me thinking, because I enjoy running Meta Llama-3 locally on my desktop pc, which has a RTX 3090, and I was curious to compare the performance between that and my Thinkpad: long story short, it is much better than I thought, and you can see for yourself here (I suggest to watch it in 4K, so that the text is readable)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fp6Ohv8JXJF8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dp6Ohv8JXJF8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fp6Ohv8JXJF8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/517e3e074fa5cd05c9f421dc805c6426/href">https://medium.com/media/517e3e074fa5cd05c9f421dc805c6426/href</a></iframe><p>Getting to the result you see in the video was not exactly straightforward: there’s a <a href="https://github.com/intel/intel-npu-acceleration-library">GitHub repo</a> for the Python and the underlying C++ library, but I had to jump through a few hoops to make it work: I am documenting them here in case this is helpful for others.</p><h3>Compiling the Python package from source</h3><p>As you can see in the instructions it says that there’s a binary package that you can just download and install into your Python virtual environment, however, at least at the time of writing, said package is out of sync with their main branch: by that I mean that the examples reference functions and classes that are not in the library, so they will fail to run.</p><p>To build it you will need to install all the necessary tools: in Windows that means installing the latest Visual Studio Community, making sure that in the installer you select <em>Desktop development with C++</em>. Unfortunately following the instructions did not help me, because apparently the generated paths were too long and that resulted in a build failure, so what I did was to checkout the library branch in the shortest path I could think of (C:\n) and build the python binary package (a.k.a. <em>wheel</em>) from there. Doing so solved the issue and allowed me to later install it and run Llama 3</p><h3>Benchmarking Llama 3</h3><p>I will now show some metrics for the following prompts:</p><ul><li>How are you? Please keep your answer short and on point</li><li>Is 2 a prime number? Please keep your answer short and on point</li><li>Is Zaire a country? Please keep your answer short and on point</li><li>Why is the sky blue? Please keep your answer short and on point</li><li>What are the main components of a transformer neural network architecture? Please keep your answer short and on point</li><li>Is Rome a capital city? Please keep your answer short and on point</li><li>Who was Lee Kuan Yew? Only answer with the most important points</li></ul><h3>A word on tokens</h3><p>I will especially be focusing on how many <em>tokens </em>per second the model was able to generate. This is because this metric is widely used when benchmarking (and billing the usage of) LLMs. I won’t go too much into the details, but basically a token is part of a word. It is not necessarily a syllable, i.e. the word <em>cosmopolitan </em>is tokenized by Llama 3<em> </em>as <em>cos-m-opolitan </em>and each model tokenizes in its own way.</p><h3>The actual benchmarks</h3><p>I run these prompt 4 times while connected to power, and 4 times while on battery, using a <a href="https://github.com/enricorampazzo/llama3-npu-test/blob/main/llama3.py">python script</a>. No other user app was running (i.e. nothing except background Windows services)</p><p>Here are some overall results</p><p>When <em>connected to power</em>:</p><ul><li>Average tokens per second: 1.910</li><li>Max tokens per second: 2.096</li><li>Min tokens per second: 1.616</li></ul><p>When <em>on battery</em>:</p><ul><li>Average tokens per second: 1.353</li><li>Max tokens per second: 1.601</li><li>Min tokens per second: 0.466</li></ul><p><em>(these bullet points are curtesy of Medium, that does not (yet?) support HTML tables, despite them having being introduced in January 1997.)</em></p><p>From the raw numbers it seems like there’s a substantial performance penalty when running on battery, and this is confirmed when looking at the average tokens per second generated for each prompt (the dark blue slice represents the generation speed when on battery)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fllama3-npu-test-s55czbtsm3qdpshgki8iyp.streamlit.app%2F%3Fembed%3Dtrue&amp;display_name=Streamlit&amp;url=https%3A%2F%2Fllama3-npu-test-s55czbtsm3qdpshgki8iyp.streamlit.app&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fs4a-prod-share-preview%2Fdefault%2Fst_app_screenshot_image%2Ffdea9e1e-6de6-4b3d-b962-e674cbbed735%2FHome_Page.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamlit" width="560" height="630" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e36ad4cf08adf412bb1312777acfe02/href">https://medium.com/media/4e36ad4cf08adf412bb1312777acfe02/href</a></iframe><h3>Generating while on battery: calculating milliwatts per hour (mWh) per token</h3><p>Now, I wanted to see how energy intensive token generation is.</p><p>It was more complicated than I anticipated: basically getting the battery level as a percentage is quite easy, but it is also quite meaningless: 2% can be a lot or not so much depending on the actual battery size. To get the data I used a Windows utility called <a href="https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/powercfg-command-line-options">powercfg</a>, which creates a battery report in HTML or XML that includes the current charge level in milliwatts: I called it right before and right after the model did its generation, and calculated the delta: not perfect, but good enough to get an idea.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fllama3-npu-test-s55czbtsm3qdpshgki8iyp.streamlit.app%2Fmwh_per_token%3Fembed%3Dtrue&amp;display_name=Streamlit&amp;url=https%3A%2F%2Fllama3-npu-test-s55czbtsm3qdpshgki8iyp.streamlit.app%2Fmwh_per_token&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fs4a-prod-share-preview%2Fdefault%2Fst_app_screenshot_image%2Ffdea9e1e-6de6-4b3d-b962-e674cbbed735%2Fmwh_per_token.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamlit" width="560" height="630" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0ee8410d421dc47c1f6ecf1ad299ed7/href">https://medium.com/media/c0ee8410d421dc47c1f6ecf1ad299ed7/href</a></iframe><p>I don’t exactly understand why, but when calculating such delta for the third prompt (Is Rome a city…) it came out as 0 and this is the average of the 4 generations for this prompt, hence the corresponding bar in the chart (lack thereof). If you know a better way to monitor mWh consumption programmatically feel free to enlighten me in the comments.</p><h3>Unresolved issues</h3><p>In my test I used two more prompts, <em>Is Singapore a city or a country?</em> and <em>What is a </em><a href="https://en.wikipedia.org/wiki/Self-replicating_spacecraft"><em>Von Neumann probe</em></a>?, the reason you don’t see the result is because by the time it reached those prompt the model went probably out of memory and started spitting gibberish. This seems to be a common problem for LLMs and when running on NVIDIA GPUs there’s a handy function to reset the cache. <a href="https://github.com/intel/intel-npu-acceleration-library/issues/110">I asked</a> if something similar existed for the NPU but got no answers so far.</p><h3>Conclusion</h3><p>I genuinely think NPUs are incredibly promising: they can usher a slew of useful applications leveraging the user data in a private, power-efficient way and while we are not there yet this is just the beginning.</p><p>If you liked this post, please like and share it, if you want to connect here’s my <a href="https://www.linkedin.com/in/enricorampazzo/">LinkedIn profile</a> and if you want to hire me I am on <a href="https://www.upwork.com/freelancers/~01eefa14727e06908f">Upwork</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dd4236eb547" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to enable RTX 3090 support in fast.ai once and for all with Docker]]></title>
            <link>https://medium.com/this-time-is-different-my-journey-towards-machine/how-to-enable-rtx-3090-support-in-fast-ai-once-and-for-all-with-docker-48d8d9e5247d?source=rss-59c7fb7188d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/48d8d9e5247d</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[fastai]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[cuda]]></category>
            <dc:creator><![CDATA[Enrico Rampazzo]]></dc:creator>
            <pubDate>Wed, 16 Aug 2023 10:47:34 GMT</pubDate>
            <atom:updated>2023-08-16T10:47:34.188Z</atom:updated>
            <content:encoded><![CDATA[<p>How to enable RTX 3090 support in fast.ai once and for all with Docker</p><h3>Introduction</h3><p>As you know from my previous post, I am trying to follow the Deep Learning for Coders 2022 youtube course. I am stuck on lesson 3, but this is beside the point. As a matter of personal preference I’d rather run code locally instead of using Colab and the likes, because I have an RTX 3090.</p><p>As you also know if you have ever tried it, adding GPU support to your favourite deep learning library might not be exactly plug and play: you need to install CUDA libraries, and you need to find out which version supports your hardware. Also, it has happened that sometimes you need to shuffle .DLLs around, which is not my idea of fun (no offence)</p><h3>Docker to the rescue</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*SKB9vzcZRL3bQk846Tmjbw.jpeg" /><figcaption>Explaining Docker in one image</figcaption></figure><p>Docker is a containerization technology: say that you want to run software A, which runs on top of Linux and needs to have a bunch of libraries and configuration files installed alongside and that can be accessed as a web application.</p><p>With Docker you can create a Linux container, install software A, and then you will have an environment that you can use and distribute independently from your physical computer</p><h3>Creating the Dockerfile</h3><p>I build my image from the nvidia/cuda base image with ubuntu. To see the available tags check <a href="https://hub.docker.com/r/nvidia/cuda/tags">https://hub.docker.com/r/nvidia/cuda/tags</a></p><p>Because the cuda libraries are supposed to be backward compatible, using the newest version should be the right choice, unless your GPU is so recent that a CUDA library for it has not been released yet. As you can see I used pytorch 1.10 compiled with CUDA library v. 11.1 (torch 1.10+cu111) because it was the latest pytorch version 1 I could find and the fast.ai library has not been updated to support Pytorch 2 as far as I know</p><pre># Start from this image that contains the CUDA libraries<br>FROM nvidia/cuda:&lt;latest-version&gt;-base-ubuntu20.04<br># Add python 3.8<br>RUN apt-get update &amp;&amp; apt-get install python3.8-venv -y<br><br># Create a python virtual environment<br>RUN python3 -m venv /opt/venv<br>ENV PATH=&quot;/opt/venv/bin:$PATH&quot;<br><br># Install pytorch with support for cuda 11.1<br>RUN pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html <br><br># Install the dependencies for the course<br>RUN pip install fastbook==0.0.29 timm gradio jupyter<br><br># Create folder workspace and set it as working directory<br>RUN mkdir workspace<br>WORKDIR /workspace<br><br># Start the jupyter notebook server<br>ENTRYPOINT jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --no-browser</pre><p>The Dockerfile above will create a container that will allow you to leverage your GPU when running the course jupyter notebook. To build the image save the file above as “Dockerfile” and run</p><pre>build . -t &lt;image-name&gt;</pre><h3>Running the image</h3><p>Run this</p><pre>docker run --rm --name fastdotai_course --gpus all -p8888:8888 -v.:/workspace/lesson3 &lt;image-name&gt;A brief explanation of the options I used</pre><p><em>— rm</em>: If there’s another container with the same name, remove it to avoid naming conflicts</p><p><em>— name</em>: the contaner name</p><p><em>— gpus all</em>: allow the container to access all GPUs</p><p><em>-p8888:8888</em>: port 8888 of the container will be accessible from your computer as port 127.0.0.1:8888, which in turn will allow you to access the jupyter notebook server</p><p><em>v.:/workspace/lesson3</em>: the content of the current folder (.) will be available to the container as /workspace/lesson3, which means that you will be able to use your existing jupyter notebooks/models/data and they will not be lost when the container is killed</p><p>This will run the container in your terminal window, and from there you can see all the jupyter notebook logs. If you want to run the container in the background, so as to it will keep running even if the window is closed, add the <em>-d</em> option before<em> &lt;image-name&gt;</em></p><h3>The prize</h3><p>Open a new browser window/tab and point it to the link you see in the container logs or in the terminal window your container is running from, it looks like <em>http://127.0.0.1:8888/?token=&lt;token&gt;</em></p><p>Now create a new jupyter notebook and run</p><pre>import torch<br>torch.cuda.get_device_name(0)</pre><p>If everything went well, you should see <em>just</em> your GPU make and model, e.g.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*2ybJxu6xB8PG5GbJSdshWw.png" /></figure><h3>Setting num_workers=0 when creating a Dataloader</h3><p>Now that you are using a GPU, make sure you set numworkers=0 every time you create a Dataloader, e.g.</p><pre>dls = ImageDataLoaders.from_name_func(&#39;.&#39;,<br>    get_image_files(path), valid_pct=0.2, seed=42,<br>    label_func=RegexLabeller(pat = r&#39;^([^/]+)_\d+&#39;),<br>    item_tfms=Resize(224), num_workers=0)</pre><p>If you don’t, you are going to get errors when training your neural network, see <a href="https://github.com/pytorch/pytorch/issues/51344">https://github.com/pytorch/pytorch/issues/51344</a></p><h3>Troubleshooting</h3><h4>Checking if your GPU is really being used when training your neural network</h4><p>While training a neural network, open the task manager by pressing Control + Alt + Delete and choose Task manager &gt; Performance. Click on “GPU” in the left column, if you don’t see it scroll down. If your GPU is being used, the 3D graph should not be flat, alsop the dedicated GPU memory should be more than 1 GB</p><h4>Checking if the container is running</h4><pre>docker ps</pre><p>will return a list of all the currently running containers</p><h4>Getting the container logs</h4><pre>docker logs &lt;container name&gt;</pre><h4>Removing (shutting down) a container</h4><pre>docker rm -f &lt;container name&gt;</pre><p>will stop and shut down the container (if you don’t use -f you need to call <em>docker stop</em> first)</p><h3>Conclusion</h3><p>In this guide I explained how to leverage your GPU for deep learning in a clean and portable way using Docker. I tried to explain all the important aspects of the solution, if I left something out just write a comment below :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48d8d9e5247d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/this-time-is-different-my-journey-towards-machine/how-to-enable-rtx-3090-support-in-fast-ai-once-and-for-all-with-docker-48d8d9e5247d">How to enable RTX 3090 support in fast.ai once and for all with Docker</a> was originally published in <a href="https://medium.com/this-time-is-different-my-journey-towards-machine">This time is different: my journey towards machine learning</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My first, publicly available image classifier :)]]></title>
            <link>https://medium.com/this-time-is-different-my-journey-towards-machine/my-first-publicly-available-image-classifier-a67853042b41?source=rss-59c7fb7188d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a67853042b41</guid>
            <dc:creator><![CDATA[Enrico Rampazzo]]></dc:creator>
            <pubDate>Tue, 07 Feb 2023 19:29:42 GMT</pubDate>
            <atom:updated>2023-02-07T19:29:42.851Z</atom:updated>
            <content:encoded><![CDATA[<h3>My first, publicly available image classifier :)</h3><p>Hello,</p><p>In <a href="https://www.youtube.com/watch?v=F4tvM4Vb3A0">Lesson 2</a> of the fast.ai deep learning course it is explained how to deploy (i.e. make available for others to use) on the Internet a deep learning model using <a href="https://huggingface.co/spaces">Huggingface spaces</a>.</p><p>Here I don’t mean to replicate the lesson, first because it would reek of plagiarism and second because I think Jeremy Howard already explains it beautifully. What I am going to cover are the unexpected difficulties I encountered in an otherwise fairly straightforward process.</p><p>In my first attempt I used Gradio, a framework to programmatically create a graphical user interface, i.e. a website where someone can submit an image to my neural network for classification and see the result.</p><p>To “programmatically create a graphical user interface” basically means that you write this</p><pre>import gradio as gr<br><br># this creates the &quot;Drop Image Here&quot; box with the &quot;Clear&quot; and &quot;Submit&quot; buttons<br>image = gr.inputs.Image(shape=(192, 192))<br># this creates the &quot;output&quot; box which will contain the result of the classification<br>label = gr.outputs.Label()<br><br># These are the image files you see under &quot;Examples&quot;: you can click on any of them and they will appear in the Drop Image Here Box<br>examples = [&quot;examples/test_bathroom.jfif&quot;, &quot;examples/test_living_room.jfif&quot;, &quot;examples/test_building.jfif&quot;]<br># Assemble the above element in an interface and run it<br>intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)<br>intf.launch()</pre><p>and you get this</p><figure><img alt="an user interface where you can upload a picture and have it classified" src="https://cdn-images-1.medium.com/max/1024/1*wfZEB95Kp6b5qAjgleVZ7w.png" /></figure><p>Neat, right?</p><h3>A short description of my image classifier</h3><p>My classifier is supposed to tell you if the picture you submit shows a bathroom, a living room or buildings. I chose to do this because ages ago, this was an assignment that I could have chosen to carry out as part a machine learning course I was attending at the time: build a classifier to tell if a picture shows an indoor or an outdoor image, and to me it seemed like an impossible problem: suffice to say that with the fast.ai library it was almost trivial to do.</p><p>You can try it out <a href="https://huggingface.co/spaces/giustiniano/real_estate_classifier">here</a></p><p>And now for the list of issues and how I solved them:</p><h3>Loading the model in Windows causes an issue with PosixPath</h3><p>As explained in the lesson, you should load your model as follows</p><pre>load_learner(&quot;my_model.pk1&quot;)</pre><p>however, if you are using Windows you get this error</p><p>NotImplementedError: cannot instantiate &#39;PosixPath&#39; on your system</p><p>The workaround for this is to load pathlib and to assign to PosixPath WindowsPath, as follows</p><pre>if platform.system().lower() == &quot;windows&quot;:<br>    import pathlib<br>    posix_path = pathlib.PosixPath<br>    pathlib.PosixPath = pathlib.WindowsPath<br>learner = load_learner(&quot;room_classifier.pk1&quot;)<br>if platform.system().lower() == &quot;windows&quot;:<br>    pathlib.PosixPath = posix_path</pre><h3>Gradio does not like numpy newer than 1.4</h3><p>So, I followed the instructions but when I tried to classify an image clicking on the Submit button, I had this rather confusing message:</p><p>‘numpy’ has no attribute ‘int’</p><p>After digging for a bit, it turns out that Gradio relies on numpy having an ‘int’ function that was removed in numpy after version 1.4, so Gradio is calling something that does not exist and fails in the process</p><p>Solution: in your requirements.txt file you can set</p><pre>numpy&lt;1.4</pre><h3>Huggingface spaces does not like binary files</h3><p>So, you trained your neural network and you have the resulting model. You would like to upload it to your Huggingface spaces repository so that your program can use it to classify images. Also, you want to upload some images to use as examples</p><p>Problem: Huggingface spaces is configured to disallow to push binary files in your git repository</p><p>Solution: Use git-lfs to track your binary files as follows</p><pre>git lfs track ./my_shiny_new_model.pk1<br>git lfs track ./my_example_image.jpg</pre><p>and so on and so forth for all the binary files you want to upload</p><p>then call</p><pre>git-lfs install</pre><p>so that git will update/create the .gitattributes file to treat those files as binary, then commit and push as usual</p><p>I hope this was helpful, see you next time :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a67853042b41" width="1" height="1" alt=""><hr><p><a href="https://medium.com/this-time-is-different-my-journey-towards-machine/my-first-publicly-available-image-classifier-a67853042b41">My first, publicly available image classifier :)</a> was originally published in <a href="https://medium.com/this-time-is-different-my-journey-towards-machine">This time is different: my journey towards machine learning</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Capitain Marvel]]></title>
            <link>https://medium.com/@Enrico_Rampazzo/capitain-marvel-4febbdffd469?source=rss-59c7fb7188d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4febbdffd469</guid>
            <dc:creator><![CDATA[Enrico Rampazzo]]></dc:creator>
            <pubDate>Sat, 09 Mar 2019 18:56:31 GMT</pubDate>
            <atom:updated>2019-03-09T18:56:31.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OP_vj7OSozOMY6a8QHlvOA.jpeg" /><figcaption>al netto della bellezza, sembra la mia faccia quando qualcosa non compila</figcaption></figure><p>Ieri sono uscito prima dal lavoro, e siccome il tempo era uno schifo (hello UK), ho ben pensato di chiudermi nell’apposito cinema IMAX 3D e di guardare Capt. Marvel.</p><p>Il film mi è piaciuto molto. Penso che, vista la trama ed I personaggi, farlo uscire in concomitanza con la Festa della Donna sia stata una scelta molto appropriata.</p><p>La mia comprensione del marketing è tutto sommato equivalente a quella che ho della fisica nucleare (tiri una biglia addosso a delle altre biglie e alla fine esplode tutto, giusto?), e tuttavia credo che il target più giovane fosse quello degli “<a href="https://www.good.is/articles/generation-xennials">xennial</a>”: I monitor CRT, i cercapersone, il ronzio caratteristico delle connessioni dial-up, le ricerche su AltaVista mi hanno fatto scendere la lacrimuccia, lo ammetto.</p><p>Ci sono stati altri due momenti che mi hanno quasi commosso: da un lato il cameo di Stan Lee ed un altro, di cui non parlerò per non fare spoiler.</p><p>Passando al cast, Brie Larson è un’attrice che ho amato dai tempi di <a href="https://www.imdb.com/title/tt3170832/">Room</a>, un film bellissimo che però non ho mai avuto il coraggio di riguardare. Qui la sua interpretazione è perfetta: una eroina umana capace di rialzarsi nonostante tutte le occasioni in cui la sua vita la fa cadere, qualcosa che la rende vicina a tutti noi comuni mortali. Certo, non mi dispiacerebbe poter sparare raggi della morte a piacimento con le mani come fa lei, ma bisogna sapersi accontentare.</p><p>Samuel Jackson…beh…fa la versione family-friendly di Samuel Jackson (quella che non dice m0th3rf***er 5 volte in 4 parole, per capirci) ed il suo mix di ironia e profondità è sempre vincente. E’ anche interessante vederlo con due occhi funzionanti, tanto per cambiare</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2t9M0VhTx8RCqNEB4V5xvA.jpeg" /><figcaption>Nick Fury, now with stereoscopic vision</figcaption></figure><p>Tutti gli altri “comprimari”, termine probabilmente inappropriato ad un film corale come questo, sono ben definiti, e credibili (nei limiti di un film di fantascienza). Poi ce n’è uno che è pucciosissimo, il micione rosso!! Marvel, un personaggio del genere sicuramente merita il suo spin-off, ci conto!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*mYJ9hllavnfJ9xNtP1LMmQ.jpeg" /><figcaption>Non si vede, ma Carol fa la faccia che fanno le persone normali quando vedono me che gioco con un gatto</figcaption></figure><p>Dal punto di vista tecnico, gli effetti speciali sono generalmente fatti molto bene e vale la pena vederlo in 3D se potete. L’unica pecca, a mio personalissimo parere, si ha quando Carol Denvers va il “full god mode”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OSTtp1N_WdkmVsRY9-SatA.jpeg" /><figcaption>Ecco cosa si intende per “lighten up”…</figcaption></figure><p>Non so di preciso cosa non mi convinca di questo effetto speciale, forse che si perdono un po’ i bei lineamenti di Brie.</p><p>Passando ai contenuti, il film tratta, nei limiti del medium e del genere, problemi attuali, nella migliore tradizione della fantascienza nobile: in questo caso si tratta di temi come i rifugiati, la relatività delle categorie amico / nemico ed il ruolo delle donne.</p><p>Magari qualcuno si è triggerato perché c’è una scena di “womansplaining” (letteralmente una) ma personalmente ho apprezzato molto il fatto che la protagonista fosse una donna forte, intelligente e che non ha bisogno di andare in giro mezza svestita e / o con tacchi stratosferici per essere bellissima: d’altronde, non so voi, ma se io dovessi salvare il mondo, con tutte le seccature che questo comporta, non lo farei certo su un tacco 12.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4febbdffd469" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oculus Rift + Touch: first contact]]></title>
            <link>https://medium.com/@Enrico_Rampazzo/oculus-rift-touch-first-contact-780779761c51?source=rss-59c7fb7188d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/780779761c51</guid>
            <category><![CDATA[oculus-touch]]></category>
            <category><![CDATA[oculus-rift]]></category>
            <dc:creator><![CDATA[Enrico Rampazzo]]></dc:creator>
            <pubDate>Sun, 11 Jun 2017 20:54:15 GMT</pubDate>
            <atom:updated>2017-06-11T21:28:43.009Z</atom:updated>
            <content:encoded><![CDATA[<p>Some days ago I asked a colleague of mine about the Touch Bar on his new MacBook, how it was, did he like it. He said that it was sometimes useful, but it wasn’t, obviously, a transformative experience.</p><p>“Transformative experience” is the only expression I can think of to describe my first impression of the Rift with Touch controllers. At first, I focused on the fact that the image quality was far from perfect (720p per eye), but after a very short while I was completely sucked in, in no small part because of the Touch controllers: the fact that I could reach for objects, manipulate and throw them was…well…difficult to describe, but well worth not just the expense for the whole thing, but also the hassle of setting it up (more on that in a separate article).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8M_jpUhSu50oxazn378URg.png" /><figcaption>Rise and shine Dr. Fre…ehm…sorry, different game</figcaption></figure><p>The first tutorial is very brief, and just makes sure you get to know the various buttons on the Touch controllers. After that, you end up in a sort of garage / lab full of different gadgets, and a Wall-Esque robot, which you activate by closing a hatch on its head (using your hands, of course).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jSuqNQnrQvoLBF59ZCN_Ig.png" /><figcaption>Hi there!</figcaption></figure><p>After waking up, it starts playing hide-and-seek, and at some point waves at you, at which point, you wave back at it.</p><p>After, it comes closer, and holds a few Zip cartridge-like disks. What? You don’t know what a <a href="https://en.wikipedia.org/wiki/Zip_drive">Zip Cartridge</a> is?? Ah, these youngsters…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oT0Gi82SQLu8cIUCLd4hLQ.png" /><figcaption>I won’t hurt you</figcaption></figure><p>You can put them in a 3D printer just next to you, which will “print” different things for each “Zip Cartridge”. For example, one creates butterflies, and if you gently put your hand close to them they will rest on the tip of your finger.</p><p>Another disk “prints” some toy missiles (no, not like the ones the Donald has: those are real and dangerous, whether he realizes it or not), but you can’t do much with them, just throw them and alas, they don’t explode. Sad!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WyrVrvD3biB9coWww16GJg.png" /><figcaption>My outer child, unleashed (more than usual)</figcaption></figure><p>A third disk creates handheld bells, the one a baby would use to play: I found that an appropriate reminder that an Oculus is just a toy for grown-ups, and a very expensive one at that. But hey, IT IS SOOOO COOOL!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gxu1OBz62P9SrdE9JOHfsQ.png" /><figcaption>“POW” appears when you actually hit one of the targets. Honest!</figcaption></figure><p>Another disk creates a “gun”, which you can use to fire at moving targets. Of course my aim is horrible, but I managed to hit something, laws of statistics and all.</p><p>After that, the final disc, with an O on the “label”, takes you out of there into Oculus Home. Time to wave goodbye to Wall-E :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b52kA6ViF5Ekq2hxXLUfZQ.png" /><figcaption>Goodbye Wall-E, nice meeting you</figcaption></figure><p>I hope this gave you a hint of how Oculus Rift + Touch “feels”: it is not perfect, but it is awesome :)</p><p>For the more technically — inclined, I will post an article on my hard-learned lessons on how to set up the whole thing. Stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=780779761c51" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[X-Men, l’olocausto e la storia che non insegna]]></title>
            <link>https://medium.com/@Enrico_Rampazzo/x-men-lolocausto-e-la-storia-che-non-insegna-1541a44b077d?source=rss-59c7fb7188d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1541a44b077d</guid>
            <category><![CDATA[stato]]></category>
            <category><![CDATA[marx]]></category>
            <category><![CDATA[tempi-moderni]]></category>
            <dc:creator><![CDATA[Enrico Rampazzo]]></dc:creator>
            <pubDate>Sat, 11 Jun 2016 01:53:03 GMT</pubDate>
            <atom:updated>2016-06-11T01:53:03.400Z</atom:updated>
            <content:encoded><![CDATA[<p>Stasera sono andato a vedere X-Men Apocalypse. l’ho trovato abbastanza scialbo, per quello che può valere la mia opinione.</p><p>Tuttavia, rivedendo i vari flashback che narrano come Magneto abbia acquisito i suoi poteri (spoiler: in un campo di concentramento), mi è riaffiorato nella memoria un ragionamento che feci ormai diversi anni fa, credo durante l’ultimo anno di scuole superiori: com’era possibile che popolazioni abituate da tempo immemore alla convivenza con “il diverso”, nella fattispecie gli ebrei, abbia cambiato atteggiamento in modo così radicale e, tutto sommato, repentino? Com’era possibile che leggi liberticide fossero state recepite tutto sommato senza causare troppa opposizione?</p><p>Certo, c’era stata la più grande crisi economica di sempre, ma poteva questo, da solo, spiegare tutto? Mi sembrava una spiegazione insufficiente.</p><p>Vedendo come gira il mondo nell’anno di grazia (?) 2016, mi rendo conto che avevo capito assai poco sia di come girasse il mondo allora, sia di come giri adesso.</p><p>Forse aveva ragione Marx quando parlava di una struttura economica che stava alla base di altre sovrastrutture giuridiche e culturali: appena la struttura economica comincia a cedere, i diritti umani latu sensu vengono meno. E, quel che è peggio, il tutto è democraticamente legittimato, dove, per democrazia si intende la dittatura della maggioranza.</p><p>Cosa è andato storto? Molte cose, probabilmente: da un lato, gli Stati non hanno saputo fare quello che dovrebbero, ovvero accumulare risorse quando l’economia va bene per potersi permettere misure anticicliche quando l’economia va male, e se non l’hanno fatto è soprattutto per ragioni di consenso. D’altra parte la scuola di massa non è riuscita a formare un elettorato capace di esercitare la sua funzione, a giudicare dal numero di antivaccinisti, terrapiattisti, signoraggisti e sovranisti che vedo in giro.</p><p>Comunque sia, ho capito come si possa essere tutto sommato passivi di fronte a comportamenti abberranti (rifugiati lasciati dietro il filo spinato, il candidato repubblicano alla casa bianca che propone un muro con il messico e la deportazione di 11 milioni di immigrati, ecc) : quando queste misure sono tutto sommato popolari, o si è d’accordo, o ci si trova soli con la propria voce, puerile o meno che sia.</p><p>E fare qualcosa, qualsiasi cosa, diventa difficile.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1541a44b077d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Il mio primo anno all’estero: l’Italia non mi manca]]></title>
            <link>https://medium.com/@Enrico_Rampazzo/il-mio-primo-anno-allestero-l-italia-non-mi-manca-b4247ebae533?source=rss-59c7fb7188d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4247ebae533</guid>
            <category><![CDATA[italiani-allestero]]></category>
            <dc:creator><![CDATA[Enrico Rampazzo]]></dc:creator>
            <pubDate>Sat, 04 Jun 2016 11:58:31 GMT</pubDate>
            <atom:updated>2016-06-04T11:58:31.677Z</atom:updated>
            <content:encoded><![CDATA[<p>E’ passato quasi un anno da quando sono partito per lavorare all&#39;estero: ho lavorato 5 mesi ad Amsterdam e da 6 mesi sono a Cambridge (UK). Penso di poter fare un primo bilancio della mia esperienza: non tornerei indietro, e di certo, non tornerei a lavorare in Italia.</p><p>Con questo non voglio dire lavorare all&#39;estero sia sempre meglio che lavorare in Italia: la mia prima esperienza, ad Amsterdam, non è stata delle migliori in termini di ritmi di lavoro e colleghi, ma, se non altro, lo stipendio è sempre molto più alto.</p><p>Vorrei sfatare alcuni miti che sento spesso:</p><ul><li>Gli stipendi non sono veramente migliori, perché il costo della vita è maggiore: posso solo dire che qui, con il stipendio di lavoratore dipendente, posso permettermi un appartamento (non molto grande, ma perfetto per me), in centro. In Italia, con il mio stipendio di dipendente, avrei fatto fatica a potermene permettere uno in periferia, infatti stavo dai miei.</li><li>Il lavoro è più difficile: Non direi. La web application su cui lavoravo ad Amsterdam non era più complicata di quella su cui ho lavorato in Italia per quasi due anni, o di quella che scrissi precedentemente per BMW Italia. Il lavoro che faccio ora è difficilmente comparabile con quello che ho fatto in Italia, ma si tratta, come sempre, di acquisire la conoscenza del dominio di applicazione.</li></ul><p>La cosa che più mi ha colpito qui a Cambridge è la dinamicità dell’azienda, soprattutto per quanto riguarda il livello manageriale: in Italia spesso mi sono trovato dei capi di grande esperienza, ma non sempre ferrati o interessati sulle nuove tecnologie, ma questo probabilmente c’entra meno con Cambridge o con l’Italia e di più con il fatto che ora lavoro per una startup, mentre in precedenza erano sempre grandi aziende.</p><p>In conclusione, sono davvero felice del mio traguardo: finalmente sono in una azienda dove sento di poter fare carriera pur non essendo un “commerciale” e dove ho uno stipendio che mi permette di avere la mia vita indipendente.</p><p>No, non tornerei indietro.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4247ebae533" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>