Google's DistBelief Clone Project on Apache Hama


 Deep Learning has become a household buzzword these days. Google, Microsoft, and Tencent have developed distributed deep learning systems but, these systems are closed source softwares. Many of open source softwares such as DeepDist, Caffe, ..., etc are data parallel only. In this blog post, I introduce an Artificial Neural Network implementation of Apache Hama ML package and future design plan for supporting both data and model parallelism.

1. Artificial Neural Network of Hama ML Package

 The lastest Apache Hama provides distributed training of an Artificial Neural Network using its BSP computing engine (the initial code was contributed by Yexi Jiang, a Hama committer, Facebook). In general, the training data is stored in HDFS and is distributed in multiple machines. In Hama, two kinds of components are involved in the training procedure: the master task and the groom task. The master task is in charge of merging the model updating information and sending model updating information to all the groom tasks. The groom tasks is in charge of calculate the weight updates according to the training data.

 The training procedure is iterative and each iteration consists of two phases: update weights and merge update. In the update weights phase, each groom task would first update the local model according to the received message from the master task. Then they would compute the weight updates locally with assigned data partitions (mini-batch SGD) and finally send the updated weights to the master task. In the merge update phase, the master task would update the model according to the messages received from the groom tasks. Then it would distribute the updated model to all groom tasks. The two phases will repeat alternatively until the termination condition is met (reach a specified number of iterations).

 The model is designed in a hierarchical way. The base class is more abstract than the derived class, so that the structure of the ANN model can be freely set by the user, as long as it is a layered model. Therefore, the Perceptron, Auto-encoder, Linear and Logistic regressor can all be uniformly represented by an ANN.

2. Future Plan for Large Scale Deep Neural Network

2.1 Architecture

 As described in above section, currently the data parallelism is only used. Each node will have a copy of the model. In each iteration, the computation is conducted on each node and a final aggregation is conducted in one node. Then the updated model will be synchronized to each node. So, the performance is one thing; the parameters should fit into the memory of a single machine.

 Here is a tentative near future plan I propose for applications needing large model with huge memory consumptions, moderate computational power for one mini-batch, and lots of training data. The basic idea of data and model parallelism is use of the remote parameter server to parallelize model creation and distribute training across machines, and the region barrier synchronization per task group instead of global barrier synchronization for performing asynchronous mini-batches within single BSP job. Each task group works asynchronously, and trains large-scale neural network model using assigned data sets in BSP paradigm. The below diagram shows an example of 3 task groups:


 Each task asynchronously asks the Parameter Server who stores the parameters in distributed machines for an updated copy of its model, computes the gradients on the assigned data, and sends updated gradients back to the parameter server. This architecture is inspired by Google's DistBelief (Jeff Dean et al, 2012).

2.2 Neuron-centric programming model

 The new Programming API proposed by Edward J. Yoon will provide two user-defined functions, which the user can define the characteristic of artificial neural network model: Activation function and Cost function.


 Each function can be implemented by extending ActivationFunction and CostFunction abstract classes like below:

  /**
   * User-defined sigmoid actiavation function
   */
  public static class Sigmoid extends ActivationFunction {
    @Override
    public double apply(double input) {
      return 1.0 / (1 + Math.exp(-input));
    }

    @Override
    public double applyDerivative(double input) {
      return input * (1 - input);
    }
  }

 The following properties are specified in the Job configuration:

  • The model topology: including the number of neurons (besides the bias neuron) in each layer; the type of squashing function; the degree of parallelization for each layer. 
  • The learning rate: Specify how aggressive the model learning the training instances. A large value can accelerate the learning process but decrease the chance of model convergence. Recommend in range (0, 0.5]. 
  • The momemtum weight: Similar to learning rate, a large momemtum weight can accelerate the learning process but decrease the chance of model convergence. Recommend in range (0, 0.5]. 
  • The regularization weight: A large value can decrease the variance of the model but increase the bias at the same time. As this parameter is sensitive, it's better to set it as a very small value, say, 0.001.

 The following is the sample design regarding how to create a job for training of three-layer neural network:

  public static void main(String[] args) throws Exception {
    ANNJob ann = new ANNJob();

    // set learning rate and momentum weight
    ann.setLearningRate(0.1);
    ann.setMomentumWeight(0.1);

    // initialize the topology of the model
    // set the activation function and parallel degree.
    ann.addLayer(featureDimension, Sigmoid.class, numOfTasks);
    ann.addLayer(featureDimension, Sigmoid.class, numOfTasks);
    ann.addLayer(labelDimension, Sigmoid.class, numOfTasks);
  
    // set the cost function to evaluate the error
    ann.setCostFunction(CrossEntropy.class);
    ...
  }

 In closing this blog post, I would like to request your feedback about design ideas. Please feel free to drop a comment or send a mail to our dev@hama.apache.org mailing list. Thanks.

2015년 나는 어떻게 살았나? 상반기 결산 하반기 계획

 2015년 상반기 짧다면 짧고 길다면 긴 6개월, 알차게 보낸것 같아 뿌듯하네. 다음은 월별 이벤트다:


 1월: 1월 2일 부터 3주간 새로운 조직합류를 위해 합숙교육 다녀오다.
 2월: 구정 때문에 특별한 일 없이 지내다.
 3월: Apache Software Foundation 정식 멤버로 선임되다.
 4월: Hama 그래프 패키지 성능을 개선하다. Giraph 대비 느리지 않다고.
     코드를 보면서 느낀 것은, 그 동안 너무 Memory 최적화에 빠져있었다.
     Hardware modernization을 꾸준히  고려해야한다.
 5월: 창업하고서 1년 정도 손을 놓고 있던 Apache Hama 드디어 0.7 릴리즈!
     성능개선, 그리고 Yarn 모듈과 Mesos 모듈을 탑재했다.
     Durability만 확보하면 1.0으로 커팅할 수 있으리라.
 6월: Apache Incubator PMC가 되었다.
     그리고 지난 12월 06일 태어난 내 아들은 이제 7개월이 되었다.






 하반기는 기계학습과 딥 러닝에 포커싱해볼 계획이다. 과거 내가 기계학습과 딥 러닝에 베팅할 쩍에 빅 데이터 시장은 데이터 가공 분야에 열을 올리고 있었고, 많은 지인들은 "오늘의 먹거리와 내일의 먹거리"라는 표현을 많이 썼는데 과연 그럴까?

 많은 IT 선진 기업들은 해당 분야의 연구 결과를 이제 서비스로 하나 둘 선보이고 있다. 여러 메신저 서비스들과 구글 포토가 대표적이지 않을까 싶네. 기술 발전이 가장 빠른건 오픈소스가 아니라 생존 진화압이 높은 바로 산업계였던 것 같다.

 과거엔 소프트웨어 기술 진입장벽이 낮아 로컬에서 빠른 카피 전략이 가능했지만 이제 점점 따라잡기 힘든 격차를 만들어 내고 있는만큼 주변에 휘둘리지 않고, 내가 멀리 바라보는 비전을 믿는 그대로 추진해볼 계획이다. 그것이 불혹(不惑)이겠지.

인공신경망 (Artificial Neural Network)

 우리네 인간의 학습 능력은 어떤 메커니즘으로 작동하는가? 비밀은 신경망에 있다.

1. 인간 신경망

 대뇌피질의 신경세포는 다음과 같이 수상돌기(dendrite)를 통해 다른 여러 신경세포로부터 입력 신호를 받아, 세포체(cell body)에서 정보 연산을 처리하고 축색(axon)을 통해 처리된 정보를 다른 신경세포로 전달한다. 이러한 신경세포는 시냅스라는 가중 연결자(weighted connectior)로 여러 층의 신경망을 구성한다.


 세포체에서의 연산은 입력 신호들의 합을 구하고 그것이 일정한 임계치가 되면 축색이 활성화되어 스파이크를 일으켜 다른 신경세포로 전기 신호를 전달한다. 이러한 특성을 모방하여 만든 것이 인공 신경망(artificial neural network)이다.

2. 인공 신경망

 하나의 인공 신경세포(perceptron)는 다음과 같이 n개의 입력 x1, x2, ..., xn에 대해 연결 강도 w1, w2, ..., wn에 따른 가중치를 곱하여 모든 값의 합(summation)을 구한다. 수식으로 표현하면, u = Σwixi


 이 가중치의 합은 다시 활성화 함수(activation function)를 통과해서 다음 신경세포로 전달될 출력을 결정한다. 위 축색에 활성화 함수는 0 또는 1로 출력하는 계단식 함수가 표현되어 있지만 이부분을 사용자 정의 함수로 원하는 특성을 가진 인공신경망 모델을 구현할 수 있다. 아래는 공돌이식 다이어그램.


 이렇게 활성화 함수를 정의하여 하나의 인공 신경세포에 대한 모델이 정립되면, 다음엔 이들의 연결구조를 고려한다. 우리는 다층 퍼셉트론을 볼 것이기 때문에 입력층과 출력층 사이에 1개 이상의 은닉층을 가지는 구조의 다층 신경망 구조를 한번 보자.


 이러한 신경망 구조에서의 학습은 시냅스의 연결 강도(weight)를 변화시키는 것인데 가장 기본적인 방법은 헤브의 학습 규칙으로 연결된 두 신경세포가 동시에 활성화되면 가중치를 증가시키는 방법이다. 해당 블로그에서 우리는 보다 진화한 오류역전파 알고리즘을 중점적으로 파기로 한다.

3. 다층 퍼셉트론

 다층 퍼셉트론은 인공 신경세포 퍼셉트론을 이용한 XOR문제를 먼저 이해해야하는데, 퍼셉트론 패턴 분류의 약점으로 선형 판별함수 때문에 XOR과 같은 출력을 내도록 경계선(hyperplane)을 만드는게 불가능하여 비선형 경계선을 만들기 위해 은닉층을 추가한게 다층 퍼셉트론이다.

 이제 곧 퇴근을 위하여, 구체적인 다층 퍼셉트론과 하마의 mini SGD기반 MLP 알고리즘으로 분류하는 기법은 다음 글에서 만나기로 하며 마친다.

Neural Networks와 Deep Learning

뉴럴 네트워크나 딥 러닝 알고보면 별 것 없다. 가령, 꼬리달린 이것은 고양이다 하고 조낸 인풋을 받아 들이면서 그냥 학습하면 되는 것.

이러한 이미지 인식 및 분류는 어떻게 하는거냐?

모든 이미지는 2차 배열이고 각 셀은 RGB 세 가지 색상으로 표현될 수 있는데 이를 납작한 1차원 배열, 즉 열벡터로 만든다. 당연히 1차 배열 사이즈는 height * width * 3. 이걸 클래시파이어로 학습하고 분류하면 되는데, 이러한 방식은 뉴럴 네트워크나 딥 러닝이나 똑같다. 이미지, 음성, 음원 데이터 등 인풋 특성에 따라 적당히 노멀라이제이션을 해줘도 된다.

차이점은 학습과 분류하는 방법이 다른데 통계 방식과 하이퍼플랜 기반 클래시파이어 대비 뉴럴 네트워크와 딥 러닝은 학습 방법이 인간의 뇌 구조를 닮은거다. 성능이 좋은데 왜 결과가 그러한지 수학적 해석이 어렵다. 아니, 이게 성능이 좋다라기보다는 그 결과가 그냥 인간과 비슷하다고 하는게 맞는 표현이다.

그러면 이 기술은 어떻게 활용될수 있을까?

데이터는 텍스트에서 멀티미디어로 바뀌고 있고, 전세계에서 일어나는 현상 정보를 구글 브레인이 학습하고 있다. 음성으로 뉴스를 조회하고 원하는 사진을 찾게 해주지. 인터넷에 스팸과 19금 저질 컨텐츠를 사람이 아닌 기계가 걸러낸다. 또, IoT 센싱기술이 발달할수록 기계학습과 딥 러닝의 분야는 무궁무진해진다. 더 이상 사람이 할 수 없어.